Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intellisense fails to detect package.json import paths #61504

Open
anthonyma94 opened this issue Mar 29, 2025 · 1 comment
Open

Intellisense fails to detect package.json import paths #61504

anthonyma94 opened this issue Mar 29, 2025 · 1 comment
Labels
Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone

Comments

@anthonyma94
Copy link

anthonyma94 commented Mar 29, 2025

πŸ”Ž Search Terms

  • path completion
  • node.js import path intellisense

πŸ•— Version & Regression Information

  • Tested on TS 5.7.3 with VSC 1.98.0 and 5.8.2 with VSC 1.98.2

⏯ Playground Link

https://github.com/anthonyma94/path-completion-repro

πŸ’» Code

package.json

  "imports": {
    "#foo/*": {
      "types": [
        "./src/foo/*.ts",
        "./src/foo/*"
      ],
      "default": [
        "./src/foo/*"
      ]
    }
  },

src/foo/test.ts

export const testFunc = () => {}

src/index.ts

import { testFunc } from "#foo/test";

testFunc();

πŸ™ Actual behavior

Repro for #52460.

Path completion intellisense kicks in for symbol resolution:

Image

But not path resolution:

Image

πŸ™‚ Expected behavior

I expect Intellisense to work for both scenarios.

Additional information about the issue

No response

@RyanCavanaugh RyanCavanaugh added Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases labels Mar 31, 2025
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Mar 31, 2025
@mkvlrn
Copy link

mkvlrn commented Apr 3, 2025

I've reached a scenario that is working for me but I really don't think it is supposed to be done this way, because I ended up not needing file extensions for imported modules while not in bundler moduleResolution:

/** package.json */

{
// ...
  "type": "module",
  "imports": {
    "#*": {
      // just worked like this, didn't need a "proper" recursive glob like "./src/**/*.ts"
      "dev": "./src/*.ts",
      // same here
      "default": "./build/*.js"
    }
  },
// ...
}
/** tsconfig.json */

{
// ...
  "customConditions": ["dev"], // this was key
  "esModuleInterop": true,
  "isolatedModules": true,
  "lib": ["ESNext"],
  "module": "NodeNext",
  "moduleResolution": "nodenext",
  "target": "esnext",
// ...
}
/** src/lib/basic-math.ts */

export function add(a: number, b: number): number {
  return a + b;
}
/** src/main.ts */

import { add } from "#lib/basic-math";

console.log(`2 + 2 = ${add(2, 2)}`);

In main.ts I get intellisense if I manually add the "base" #lib/, but it does not suggest adding the base path itself.
Image

Running code works fine:

  • without the build step, using dev conditions to import the ts files, using node to strip types (node -C dev src/main.ts)
  • after the build step, without changing import conditions (node build/main.js)

My environment:

  • node 23.11
  • typescript 5.8.2
  • vscode 1.98.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Projects
None yet
Development

No branches or pull requests

3 participants