stream-js icon indicating copy to clipboard operation
stream-js copied to clipboard

Export ESM

Open idleberg opened this issue 3 years ago • 6 comments
trafficstars

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:

  • https://medium.com/swlh/npm-new-package-json-exports-field-1a7d1f489ccf
  • https://blog.sindresorhus.com/get-ready-for-esm-aa53530b3f77
  • https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

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/[email protected]/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"
  }
}

idleberg avatar Mar 14 '22 15:03 idleberg

I came here to say the same thing. Thanks for the workaround but any ETA on a fix?

bradintheusa avatar Jul 22 '22 21:07 bradintheusa

Does anyone have a working Vue3 client example of this? I'm just bouncing between errors at the moment.

bradintheusa avatar Jul 23 '22 23:07 bradintheusa

Hi! Any updates?

oski646 avatar Aug 16 '22 13:08 oski646

Can we give a test drive to [email protected] ? Thanks

ferhatelmas avatar Aug 31 '22 11:08 ferhatelmas

Can we give a test drive to [email protected] ? Thanks

Thanks for the heads up. I'm currently on paternal leave and won't have a chance to touch company code before December.

idleberg avatar Sep 12 '22 14:09 idleberg

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

petyosi avatar Sep 12 '22 15:09 petyosi