-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
package.json exports array #3536
Comments
The path resolution algorithm that esbuild implements for $ cat index.mjs
import foo from 'pkg/foo'
import bar from 'pkg/bar'
console.log({ foo, bar })
$ cat node_modules/pkg/package.json
{
"exports": {
"./*": [
"./src/*/index.js",
"./src/*.js"
]
}
}
$ cat node_modules/pkg/src/foo/index.js
module.exports = 'foo'
$ cat node_modules/pkg/src/bar.js
module.exports = 'bar'
$ node index.mjs
node:internal/errors:490
ErrorCaptureStackTrace(err);
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find module './node_modules/pkg/src/bar/index.js' imported from ./index.mjs
at new NodeError (node:internal/errors:399:5)
at finalizeResolution (node:internal/modules/esm/resolve:326:11)
at moduleResolve (node:internal/modules/esm/resolve:945:10)
at defaultResolve (node:internal/modules/esm/resolve:1153:11)
at nextResolve (node:internal/modules/esm/loader:163:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
at link (node:internal/modules/esm/module_job:76:36) {
code: 'ERR_MODULE_NOT_FOUND'
}
Node.js v18.16.1
$ esbuild --bundle index.mjs
✘ [ERROR] Could not resolve "pkg/bar"
index.mjs:2:16:
2 │ import bar from 'pkg/bar'
╵ ~~~~~~~~~
The module "./src/bar/index.js" was not found on the file system:
node_modules/pkg/package.json:4:6:
4 │ "./src/*/index.js",
╵ ~~~~~~~~~~~~~~~~~~
You can mark the path "pkg/bar" as external to exclude it from the bundle, which will remove this
error and leave the unresolved path in the bundle.
1 error As you can see, esbuild's behavior matches node's behavior, so I consider esbuild's behavior to be correct. |
Closing as a duplicate of #2974. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
noticing that when i specify exports like this
esbuild does not seem to find anything matching the second item - switching the order confirms that
any ideas?
The text was updated successfully, but these errors were encountered: