Skip to content

Compatibility with old TS libraries under NodeNext resolutionΒ #50482

Closed as not planned
@Jack-Works

Description

@Jack-Works

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeclinedThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions