question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getstream is currently exported as UMD only. ESM support has been around in NodeJS (and the browser) for some time and, I believe, since v12.20 it can be used without a flag. With NodeJS 16 being LTS at the time of this writing, I think it would be nice to provide an ESM export. The main advantage (for me, anyway) would be to use the same syntax when importing from a CDN and node_modules, rather than using a global variable.

Further reading:

While I don’t want to get too specific on my own code, I would like to provide an example where this would help developers. When using Vite’s development server, I can’t import getstream from without running into NodeJS-specific problems (this issue is possibly related). The same import works fine when Vite builds my code and optimizes it for the browser. Currently, my only workaround is to change the import from import stream from "getstream" to import "https://cdn.jsdelivr.net/npm/getstream@8.0.0/dist/js_min/getstream.js". However, I need to undo this change whenever I build, since I want to import the locally installed npm package of getstream. If you provided an (browser-optimized) ESM, I could simply put a condition on NODE_ENV in my config file (example below), not rewriting my import on every switch between development and build.

resolve: {
  alias: {
    "getstream": process.env.NODE_ENV ? "https://cdn.skypack.dev/getstream" : "getstream"
  }
}

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
oski646commented, Aug 16, 2022

Hi! Any updates?

0reactions
petyosicommented, Sep 12, 2022

@oski646 @bradintheusa - did you have a chance to test that?

Read more comments on GitHub >

github_iconTop Results From Across the Web

export - JavaScript - MDN Web Docs
The export declaration is used to export values from a JavaScript module. Exported values can then be imported into other programs with the ......
Read more >
Getting Started with (and Surviving) Node.js ESM
For browser and front-end application authors, the modern answer has been ECMAScript Modules ("ESM") features like import and export for ...
Read more >
Using import/export in node.js with esm | by Jamis Charles
When I started using node 6 years ago I took a quick liking to module loading in node. require() is pretty straightforward. You...
Read more >
ECMAScript modules | Node.js v19.3.0 Documentation
ECMAScript modules are the official standard format to package JavaScript code for reuse. Modules are defined using a variety of import and export...
Read more >
module.exports and ES modules (ESM) import export in Node.js
The module.exports is an object provided by Node.js and it serves to export objects or functions from a file and make it available...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found