Closed as not planned
Description
Suggestion
Improve the resolution for old ts libraries.
π Search Terms
NodeNext node_modules
β Viability Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
β Suggestion
Many libraries ships .d.ts
without .js
extension and mark them as type: "module"
.
export { a } from './file'
// ~~~~~~~~ should be ./file.js
TypeScript now treat them as error and refuse to resolve the type. This makes it even harder to adopt the new resolution mode.
π Motivating Example
Example: https://github.com/Jack-Works/ts-nodenext-legacy-library-resolution
node_modules/invalid-node-esm is a very common pattern in the current ecosystem. TypeScript failed to resolve this package as the following message:
node_modules/invalid-node-esm/dist/index.d.ts:1:15 - error TS2835: Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Did you mean './utils.js'?
1 export * from './utils'
~~~~~~~~~
src/index.ts:1:10 - error TS2305: Module '"invalid-node-esm"' has no exported member 'a'.
1 import { a } from 'invalid-node-esm'
~
This behavior is correct, but this is not usable.
π» Use Cases
Improve the compatibility and the adoption of the new resolution mode.