Skip to content

Auto import with .js extension instead of .ts with "allowImportingTsExtensions": true and package.json, imports fieldsΒ #59553

@theoludwig

Description

@theoludwig

πŸ”Ž Search Terms

"auto imports", "allowImportingTsExtensions", "package.json imports", ".js extension instead of .ts", "moduleResolution": "NodeNext"

πŸ•— Version & Regression Information

TypeScript v5.5.4

⏯ Playground Link

No response

πŸ’» Code

tsconfig.json:

{
  "compilerOptions": {
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "allowImportingTsExtensions": true
  }
}

package.json:

{
  "type": "module",
  "imports": {
    "#*": "./src/*"
  }
}

src/lib/add.ts (not really important, the content of the file, path is more important):

export const add = (a: number, b: number): number => {
  return a + b
}

src/index.ts:

import { add } from "#lib/add.js" // WRONG AUTO IMPORT, using .js, instead of .ts
console.log(add(2, 3))

πŸ™ Actual behavior

Auto import with #lib/add.js"

πŸ™‚ Expected behavior

Auto import with #lib/add.ts" because I'm using the "allowImportingTsExtensions": true config option.

This is all the more relevant since the newly added CLI Flag --experimental-strip-types in Node.js, because it enforces imports to use the .ts extension.
Ref: https://nodejs.org/docs/latest/api/typescript.html

Additional information about the issue

Related issue: #52167

Metadata

Metadata

Assignees

Labels

Fix AvailableA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions