TypeScript Version: 3.1.6, but also tried with 3.3.0-dev.201xxxxx
Search Terms: auto import json wrong module path js extension issue bug
Code
https://stackblitz.com/edit/typescript-json-import-issue
I am not using any vscode extension for managing imports and as far as I know vscode depends on typescript to show the module import suggestions, so I hope this is the right place for this issue.
tsconfig.json
{
"compilerOptions": {
"module": "es2015",
"moduleResolution": "node",
"resolveJsonModule": true,
"esModuleInterop": true
}
}
Expected behavior:
When we have:
import packageJson from './package.json';
in VSCode auto import modules autocomplete to suggest:
import { testing } from './test';
Actual behavior:
in VSCode auto import modules autocomplete suggests:
import { testing } from './test.js';
Playground Link:
Related Issues:
I think we use the presence of extension in imports to determine if we should include extensions on new imports - we should probably not include .json
(or maybe any non-ts/js extensions) in this check.
I am noticing this behavior as well, except the extension is incorrect (it's appending .js
instead of leaving it off or using the correct .ts
)
VSCode version: 1.33.1 (1.33.1)
tsconfig.json:
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"checkJs": false,
"esModuleInterop": true,
"isolatedModules": true,
"jsx": "react",
"lib": ["es2017"],
"moduleResolution": "node",
"noEmit": true,
"noImplicitAny": false,
"resolveJsonModule": true,
"skipLibCheck": true,
"target": "esnext"
}
}
i can still reproduce this on 1.38.1
I also can reproduce it in 1.41.1
Any solution for this problem?
+1. Strangely enough, started facing this recently in the last month or so - perhaps after the last update (currently on version 1.42.1).
Most helpful comment
I am noticing this behavior as well, except the extension is incorrect (it's appending
.js
instead of leaving it off or using the correct.ts
)VSCode version: 1.33.1 (1.33.1)
tsconfig.json: