Skip to content

auto-import with package.json#imports does not take moduleResolution into account #60405

Closed as not planned
@alan910127

Description

@alan910127

🔎 Search Terms

"subpath", "imports", "package.json", "moduleResolution"

🕗 Version & Regression Information

⏯ Playground Link

alan910127/ts-60405-repro

💻 Code

// package.json
{
  "imports": {
    "#*": "./src/*"
  },
  "devDependencies": {
    "typescript": "5.6.3"
  }
}
// tsconfig.json
{
  "compilerOptions": {
    "moduleResolution": "Bundler"
  }
}
// src/foo/bar/baz.ts
export function baz() {}
// src/one/two/three.ts
// actual   - import { baz } from "#foo/bar/baz.js";
// expected - import { baz } from "#foo/bar/baz";

🙁 Actual behavior

When auto-importing the function baz (either through completion or code action), the typescript language server will insert an import statement with a .js file extension.

import { baz } from "#foo/bar/baz.js";

🙂 Expected behavior

Since we are using "moduleResolution": "Bundler", it should insert an import statement without the .js file extension.

import { baz } from "#foo/bar/baz";

Additional information about the issue

I've seen a similar issue #59200, but I cannot reproduce the issue, with the same setup. Therefore, I think my issue might be related with the subpath imports.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs More InfoThe issue still hasn't been fully clarified

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions