jspm / jspm-core

JSPM Core libraries including platform builtin shims
https://jspm.org
Other
51 stars 13 forks source link

CommonJS incompatible? (events, stream) #87

Open zardoy opened 1 year ago

zardoy commented 1 year ago

to demonstrate:

console.log(typeof require("events")) // (Node.js, events npm package): function

console.log(typeof require("events")) // (from nodelibs of this package): object { default, ... }

I noticed after bundle errors like TypeError: Class extends value #<Object> is not a constructor or null of the following sample code below (coming here from esbuild plugin):

const EventEmitter = require('events');

class A extends EventEmitter {} // ...

Please ask if unclear.

guybedford commented 1 year ago

Thanks for sharing, agreed this is an important case to fix. Tracking.

chrisdostert commented 1 year ago

Thanks for all the work on this library, just sharing one place this is currently causing breaks for me. Twilio-video attempts to extend EventEmitter in quite a few classes and the above error is encountered. Just also noting, the recently released Remix v2 migrates to the jspm-core polyfills from this repo so this likely will start effecting more people.

zardoy commented 1 year ago

Thanks for all the work on this library, just sharing one place this is currently causing breaks for me.

IMO this is really huge breakage since as I understand the intention of that plugin is to support legacy code. Also, I'm curious to know why jspm was chosen instead of the classical webpack-way polyfillying? I'm using alias and banner options instead now which work fine :shrug :

guybedford commented 1 year ago

One option here might be to use package exports conditions to match a CommonJS implementation as necessary for this specific builtin. A suitable conditions might be "commonjs", defining this condition to mean "the build environment supports commonjs" (effectively the converse of the "module" condition).

guybedford commented 1 month ago

Note this story will improve with Node.js's new require(esm) support.