GetStream / stream-js

JS / Browser Client - Build Activity Feeds & Streams with GetStream.io
https://getstream.io
BSD 3-Clause "New" or "Revised" License
331 stars 110 forks source link

Export ESM #501

Open idleberg opened 2 years ago

idleberg commented 2 years ago

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"
  }
}
bradintheusa commented 2 years ago

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

bradintheusa commented 2 years ago

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

oski646 commented 2 years ago

Hi! Any updates?

ferhatelmas commented 2 years ago

Can we give a test drive to getstream@8.1.0-beta.0 ? Thanks

idleberg commented 2 years ago

Can we give a test drive to getstream@8.1.0-beta.0 ? Thanks

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

petyosi commented 2 years ago

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