Skip to content

Add exports field to support newer versions of nodejs #206

@jamie-pate

Description

@jamie-pate

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.

import makeWebsocketObservable from 'rxjs-websocket';

console.log(makeWebsocketObservable);

{
normalClosureMessage: 'Normal closure',
default: [Function: makeWebSocketObservable]
}

(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 call legacyMainResolve() if it doesn't exist (only checks the package.json main field)
https://github.com/nodejs/node/blob/v16.14.0/lib/internal/modules/esm/resolve.js#L299

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions