-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Allow subpath imports that start with #/
#62844
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
base: main
Are you sure you want to change the base?
Conversation
This aligns with Node.js PR nodejs/node#60864, which allows defining symmetric `exports` and `imports` fields in package.json: { "exports": { "./*": "./src/*" }, "imports": { "#/*": "./src/*" } }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enables TypeScript to support subpath imports starting with #/* in package.json, aligning with Node.js behavior. Previously, TypeScript rejected these patterns, but they are now valid according to Node.js PR nodejs/node#60864.
- Removed restriction that blocked
#/*import patterns - Added comprehensive test coverage for the new functionality
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/compiler/moduleNameResolver.ts | Removed check that prevented #/* subpath imports |
| tests/cases/conformance/node/nodeModulesPackageImportsRootWildcard.ts | Added test case validating #/* imports across ESM/CJS modules |
| tests/cases/fourslash/importCompletionsPackageJsonImportsPatternRootWildcard.ts | Added test for import completions with #/* pattern |
| tests/baselines/reference/nodeModulesPackageImportsRootWildcard(module=). | Generated baseline files for various module configurations |
|
Does this implementation handle multiple file extensions? I.e. if a project contains both |
|
I had assumed this would require a new module resolution mode. |
|
Yeah, technically this shouldn’t go in |
|
Shouldn't this also work with |
|
Thanks for the feedback! I'll gate this feature on NodeNext and Bundler modes. For Bundler, since it doesn't need to strictly align with Node.js versions, I think it makes sense to include it as well. One question: since this feature was just merged into Node.js (nodejs/node#60864), do we need to introduce a new module resolution mode (e.g., Node24) to represent the updated Node.js behavior? Or is gating it behind NodeNext sufficient for now? |
|
I think gating it is fine for now. |
|
Actually, it sounds like it will be backported as far back as v20, so probably we’ll want to snap the versioned module resolution at |
This aligns with Node.js PR nodejs/node#60864, which allows defining symmetric
exportsandimportsfields in package.json:{ "exports": { "./*": "./src/*" }, "imports": { "#/*": "./src/*" } }Fixes #62841