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 exports field in package.json #351

Merged
merged 2 commits into from Dec 18, 2023
Merged

Conversation

fisker
Copy link
Contributor

@fisker fisker commented Feb 14, 2022

Fixes #350

A solution that postss used seems unnecessary, as I tested, use "./*": "./*" works on Node.js 12 too.

@fisker fisker changed the title Fix exports field in package.json Fix exports field in package.json Feb 14, 2022
@fisker
Copy link
Contributor Author

fisker commented Feb 16, 2022

@kpdecker Can you take a look?

@ExplodingCabbage
Copy link
Collaborator

A solution that postss used seems unnecessary, as I tested, use "./": "./" works on Node.js 12 too.

I think you probably tested on 12.20 or later, but that it's necessary for earlier versions? The history at https://nodejs.org/docs/latest-v12.x/api/packages.html#packages_modules_packages says that support for patterns (i.e. use of *) in exports was only added in version 12.20. Some testing confirms this; if I install jsdiff from local source with npm install --save ../jsdiff and try require("diff/lib/patch/create.js"), in Node 12.19 or earlier I need ./ in the exports section or else I get:

$ node
Welcome to Node.js v12.19.1.
Type ".help" for more information.
> require("diff/lib/patch/create.js")
Uncaught:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/patch/create.js' is not defined by "exports" in /home/mark/marktest2/node_modules/diff/package.json
    at throwExportsNotFound (internal/modules/esm/resolve.js:285:9)
    at packageExportsResolve (internal/modules/esm/resolve.js:491:3)
    at resolveExports (internal/modules/cjs/loader.js:444:36)
    at Function.Module._findPath (internal/modules/cjs/loader.js:484:31)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:818:27)
    at Function.Module._load (internal/modules/cjs/loader.js:687:27)
    at Module.require (internal/modules/cjs/loader.js:903:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at repl:1:1
    at Script.runInThisContext (vm.js:120:18) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

So let's go for the postcss solution of including both ./ and ./*, just for maximum compatibility.

@ExplodingCabbage ExplodingCabbage merged commit 976d60d into kpdecker:master Dec 18, 2023
@fisker fisker deleted the exports branch December 18, 2023 23:41
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.

Can't import files in lib/
2 participants