Allow subpath imports that start with #/#62844
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.
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 |
|
Excuse my ignorance, but for a PR like this that is marked for TS 6.0, when / what is the process for this landing in TS 7? |
|
Great question! It needs to be ported now. I started microsoft/typescript-go#2330 and we'll see how that goes |
This aligns with Node.js PR nodejs/node#60864, which allows defining symmetric
exportsandimportsfields in package.json:{ "exports": { "./*": "./src/*" }, "imports": { "#/*": "./src/*" } }Fixes #62841