-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add exports field to support newer versions of nodejs #206
Comments
workaround: import { default as mwo, WebSocketFactory, WebSocketLike } from 'rxjs-websockets';
const makeWebsocketObservable = typeof mwo === 'function' ? mwo : (mwo as unknown as {default: typeof mwo}).default; |
Cool thanks for prompting me on this. You wanna open a PR? |
ok, so the output file also needs to be renamed to '.mjs' because reasons ... how do you feel about .. what a mess https://www.typescriptlang.org/docs/handbook/esm-node.html |
…sers Fixes insidewhy#206 This ensures that consumers using --experimental-modules with node 12+ will import the esm version of this package. This package's export MUST have .mjs file extension... (because otherwise the entire package must be specified as type: module) This package's export MUST use exports field in the package.json see https://nodejs.org/api/packages.html#conditional-exports Not sure how to test this with a bunch of different project styles.. webpack and other loaders _should_ be fine with importing from the `module` field with a `.mjs` file extension?
…sers Fixes insidewhy#206 This ensures that consumers using --experimental-modules with node 12+ will import the esm version of this package. This package's export must a package.json with "type": "json" (or module files must have .mjs extension)... This package's export must also use exports field in the package.json because node doesn't support the "module" field as an alternative to "main". see https://nodejs.org/api/packages.html#conditional-exports
…sers Fixes insidewhy#206 This ensures that consumers using --experimental-modules with node 12+ will import the esm version of this package. This package's export must a package.json with "type": "json" (or module files must have .mjs extension)... This package's export must also use exports field in the package.json because node doesn't support the "module" field as an alternative to "main". see https://nodejs.org/api/packages.html#conditional-exports
nodejs ignores the 'module' field of package.json and only supports the 'exports' field (which is much more vesatile) if your package is
"type": "module"
Please add the exports field to allow nodejs to load the es5m build instead of the es5 build, otherwise e.g. TypeScript with allowSyntheticDefaultImports gets confused and creates 'default' imports from the es5 build instead.
(should be
[Function: makeWebsocketObservable]
)see
https://github.com/nodejs/node/blob/v16.14.0/lib/internal/modules/esm/resolve.js#L911 where the nodejs module importer checks for the
exports
field in the packageConfig (package.json) and will calllegacyMainResolve()
if it doesn't exist (only checks the package.jsonmain
field)https://github.com/nodejs/node/blob/v16.14.0/lib/internal/modules/esm/resolve.js#L299
The text was updated successfully, but these errors were encountered: