Typescript: Vscode suggests wrong ts auto import path with js extension after having a json import

Created on 15 Dec 2018  路  6Comments  路  Source: microsoft/TypeScript


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:

Bug TSServer

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:

{
  "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"
  }
}

All 6 comments

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).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kyasbal-1994 picture kyasbal-1994  路  3Comments

manekinekko picture manekinekko  路  3Comments

blendsdk picture blendsdk  路  3Comments

weswigham picture weswigham  路  3Comments

seanzer picture seanzer  路  3Comments