Bug Report
π Search Terms
import mappings, nodenext, node16, import extensions placed wrong
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ
β― Playground Repository Link
Repository where the issue can be seen: https://github.com/vladfrangu/typescript-import-mapping-issue
π» Code
package.json
{
"type": "module",
"scripts": {
"build": "tsc"
},
"devDependencies": {
"@sapphire/ts-config": "^3.3.4",
"@types/node": "^17.0.35",
"typescript": "^4.7.2"
},
"imports": {
"#internals/*": "./dist/internals/*.js"
}
}
tsconfig.json
{
"extends": "@sapphire/ts-config",
"compilerOptions": {
"target": "ESNext",
"module": "Node16",
"moduleResolution": "Node16",
"rootDir": "./src",
"outDir": "./dist",
"paths": {
"#internals/*": ["./src/internals/*.ts"]
}
},
"include": ["src", "src/**/*.d.ts"]
}
src/internals/example.ts
export function helloWorld() {
console.log('Hello world!');
}
src/index.ts
// Attempt to import this method with your editor with the "typescript.preferences.importModuleSpecifierEnding" set to "auto"
// Then try the same autoimport with the "typescript.preferences.importModuleSpecifierEnding" set to "index"
helloWorld();
π Actual behavior
Given a package.json with import mappings, attempting to import a file defined in the mapping while typescript.preferences.importModuleSpecifierEnding is set to "auto" will cause the extension to be appended to the import, which in turn immediately causes TypeScript to report a Cannot find module '#internals/example.js' or its corresponding type declarations..
Setting typescript.preferences.importModuleSpecifierEnding to "index" works but it will have side effects for relative imports, which is not ideal.
π Expected behavior
TypeScript should only append the extension to imports that are relative, and not from imports seen from import mapping/paths. (maybe this also ties into #48120 but I am not sure if they're separate issues)
Bug Report
π Search Terms
import mappings, nodenext, node16, import extensions placed wrong
π Version & Regression Information
β―
PlaygroundRepository LinkRepository where the issue can be seen: https://github.com/vladfrangu/typescript-import-mapping-issue
π» Code
{ "type": "module", "scripts": { "build": "tsc" }, "devDependencies": { "@sapphire/ts-config": "^3.3.4", "@types/node": "^17.0.35", "typescript": "^4.7.2" }, "imports": { "#internals/*": "./dist/internals/*.js" } }{ "extends": "@sapphire/ts-config", "compilerOptions": { "target": "ESNext", "module": "Node16", "moduleResolution": "Node16", "rootDir": "./src", "outDir": "./dist", "paths": { "#internals/*": ["./src/internals/*.ts"] } }, "include": ["src", "src/**/*.d.ts"] }π Actual behavior
Given a
package.jsonwith import mappings, attempting to import a file defined in the mapping whiletypescript.preferences.importModuleSpecifierEndingis set to "auto" will cause the extension to be appended to the import, which in turn immediately causes TypeScript to report aCannot find module '#internals/example.js' or its corresponding type declarations..Setting
typescript.preferences.importModuleSpecifierEndingto "index" works but it will have side effects for relative imports, which is not ideal.π Expected behavior
TypeScript should only append the extension to imports that are relative, and not from imports seen from import mapping/paths. (maybe this also ties into #48120 but I am not sure if they're separate issues)