You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
auto-import with package.json#imports does not take moduleResolution into account #60405
// 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.
I don't think this is a bug. package.json#imports don't describe relative specifiers. Resolving #foo/bar/baz based on "#*": "./src/*" to ./src/foo/bar/baz.js would be incorrect.
The thread I linked to specifically calls out extensionless module specifiers as erroring. If they are not then perhaps that is a bug - it might be good to wait for Andrew Branch (@andrewbranch) to chime in. It would be good to understand the difference between that issue and yours.
Li-Lun Lin (@alan910127) your repo link above 404s—did you accidentally make it private? If you share the repo, I’ll investigate. Mateusz Burzyński (@Andarist) is right; the import you listed as your expected behavior should have an error.
The thread I linked to specifically calls out extensionless module specifiers as erroring. If they are not then perhaps that is a bug - it might be good to wait for @andrewbranch to chime in. It would be good to understand the difference between that issue and yours.
Hi, I'm trying to implement a just in time ui lib in a monorepo. What do u think is the best practice now to implement absolute path resolve inside this pacakge? I'm currently using both package.json subpath import along with compilerOptions.path to surpress the warning. It works fine but I just really wanna keep the logic in one place :)
Activity
Andarist commentedon Nov 4, 2024
I don't think this is a bug.
package.json#importsdon't describe relative specifiers. Resolving#foo/bar/bazbased on"#*": "./src/*"to./src/foo/bar/baz.jswould be incorrect.A related comment to this by Andrew Branch (@andrewbranch) :
#60003 (comment)
alan910127 commentedon Nov 4, 2024
Oh, I see. But TypeScript language server does not error if I use the extensionless module specifier either. Why is that the case?
Andarist commentedon Nov 4, 2024
The thread I linked to specifically calls out extensionless module specifiers as erroring. If they are not then perhaps that is a bug - it might be good to wait for Andrew Branch (@andrewbranch) to chime in. It would be good to understand the difference between that issue and yours.
andrewbranch commentedon Nov 4, 2024
Li-Lun Lin (@alan910127) your repo link above 404s—did you accidentally make it private? If you share the repo, I’ll investigate. Mateusz Burzyński (@Andarist) is right; the import you listed as your expected behavior should have an error.
xiaoyang24601 commentedon Mar 18, 2025
Hi, I'm trying to implement a just in time ui lib in a monorepo. What do u think is the best practice now to implement absolute path resolve inside this pacakge? I'm currently using both package.json subpath import along with compilerOptions.path to surpress the warning. It works fine but I just really wanna keep the logic in one place :)