-
Notifications
You must be signed in to change notification settings - Fork 291
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
With package.json "exports" resolve paths deeply with conditional rules #3993
Comments
Any help with this? having the same issue |
There is no solution besides doing it manually, for each level of nesting, i believe. |
This (mostly) works: {
"name": "pkg",
"exports": {
"./": {
"import": "./import/index.js",
"require": "./require/index.js"
},
"./*": {
"import": "./import/*",
"require": ["./require/*", "./require/*.js", "./require/*/index.js"]
}
}
} So from a CJS context: const pkg = require('pkg') /** resolves to */ 'node_modules/pkg/require/index.js'
const pkg = require('pkg/index') /** resolves to */ 'node_modules/pkg/require/index'
/** or */ 'node_modules/pkg/require/index.js'
/** or */ 'node_modules/pkg/require/index/index.js'
const pkg = require('pkg/index.js') /** resolves to */ 'node_modules/pkg/require/index.js'
const pkg = require('pkg/foo.js') /** resolves to */ 'node_modules/pkg/require/foo.js'
const pkg = require('pkg/foo') /** resolves to */ 'node_modules/pkg/require/foo'
/** or */ 'node_modules/pkg/require/foo.js'
/** or */ 'node_modules/pkg/require/foo/index.js'
const pkg = require('pkg/foo/bar') /** resolves to */ 'node_modules/pkg/require/foo/bar'
/** or */ 'node_modules/pkg/require/foo/bar.js'
/** or */ 'node_modules/pkg/require/foo/bar/index.js'
const pkg = require('pkg/foo/bar.js') /** resolves to */ 'node_modules/pkg/require/foo/bar.js' And from a MJS context: import pkg from 'pkg' /** resolves to */ 'node_modules/pkg/import/index.js'
import pkg from 'pkg/index' /** not valid, requires extension */
import pkg from 'pkg/index.js' /** resolves to */ 'node_modules/pkg/import/index.js'
import pkg from 'pkg/foo.js' /** resolves to */ 'node_modules/pkg/import/foo.js'
import pkg from 'pkg/foo' /** not valid, requires extension */
import pkg from 'pkg/foo/bar.js' /** resolves to */ 'node_modules/pkg/import/foo/bar.js' However Node accepts but only resolves the first item in an Array when supplied as a subpattern export. I have raised a bug report to hopefully change that nodejs/node#49945 If that is updated, then the package.json config above will work as expected for nested patterns. |
looks like there is a discussion on this here: nodejs/node#37928 |
It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment. |
It seems there has been no activity on this issue for a while, and it is being closed. If you believe this issue should remain open, please leave a comment. |
Details
I am trying to use the
exports
in mypackage.json
to deeply resolve module paths on top of a base path.Essentially I have this folder structure:
And I would like node to be able to resolve the paths above as if they were
/
The basic implementation of
exports
works for resolving the top level files (except thetypes
keyword isn't being picked up by TypeScript 4.7, but that's another battle for another day):This allows me to import the following without issue
In the Node documentation it describes using
*
to add conditional resolution:This doesn't allow paths nested beyond
./*/
. I have experimented with glob patterns like below but had no luckI could explicitly add each nested path into
exports
manually but I would much prefer deep folder/file resolution be handled by node directly.Any idea what I need to do to get this working?
Node.js version
Not applicable.
Example code
No response
Operating system
All
Scope
Module resolution
Module and version
Not applicable.
The text was updated successfully, but these errors were encountered: