Skip to content
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

fix esm exports in package.json files #308

Closed
wants to merge 1 commit into from

Conversation

ushi-as
Copy link
Contributor

@ushi-as ushi-as commented Dec 4, 2021

Nodejs does not allow to export directories, but it is possible to use subpath patterns to achieve this.

See https://nodejs.org/api/packages.html#subpath-patterns

Reproduce

// test.mjs
import { stringify } from 'csv-stringify/browser/esm/index.js';
$ node test.mjs
node:internal/errors:464
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './browser/esm/index.js' is not defined by "exports" in /home/xxx/test/node_modules/csv-stringify/package.json imported from /home/xxx/test/test.mjs
    at new NodeError (node:internal/errors:371:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:429:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:683:3)
    at packageResolve (node:internal/modules/esm/resolve:853:14)
    at moduleResolve (node:internal/modules/esm/resolve:910:18)
    at defaultResolve (node:internal/modules/esm/resolve:1005:11)
    at ESMLoader.resolve (node:internal/modules/esm/loader:475:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:245:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:79:40)
    at link (node:internal/modules/esm/module_job:78:36) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Node.js v17.1.0

With Node 16 you get a deprecation warning

(node:102) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./browser/esm/" in the "exports" field module resolution of the package at /home/xxx/test/node_modules/csv-stringify/package.json.
Update this package.json to use a subpath pattern like "./browser/esm/*".

@ivanoats
Copy link

ivanoats commented Dec 8, 2021

This would be great to get into a release, thank you!

@wdavidw wdavidw closed this in c48fe47 Dec 13, 2021
@wdavidw
Copy link
Member

wdavidw commented Dec 13, 2021

Thanks, while being aware of the *, I never got any warning/error even after initializing a new project. I will soon release a patch version.

@ushi-as ushi-as deleted the fix-esm-exports branch January 3, 2022 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants