question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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:

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:14
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

14reactions
cwhenderson20commented, May 9, 2019

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"
  }
}
11reactions
cscleisoncommented, Oct 5, 2019

i can still reproduce this on 1.38.1

Read more comments on GitHub >

github_iconTop Results From Across the Web

Auto import in Visual Studio Code only offering absolute path ...
I will pointout something: It is much better to have absolute path but starting from source dir (src/) like "import .. from "my-module/bla/bla/ClassName.js"Β ......
Read more >
Managing Extensions in Visual Studio Code
VS Code makes it easy to manage your extensions. You can install, disable, update, and uninstall extensions through the Extensions view, the Command...
Read more >
May 2022 (version 1.68) - Visual Studio Code
In this milestone, we have added support for deprecated extensions in VS Code. ... The Organize Imports command for JavaScript and TypeScript lets...
Read more >
Editing Python in Visual Studio Code
Tip: Check out the IntelliCode extension for VS Code. ... Pylance offers auto import suggestions for modules in your workspace and/or packages you...
Read more >
jsconfig.json Reference - Visual Studio Code
File Scope - no jsconfig.json: In this mode, JavaScript files opened in Visual Studio Code are treated as independent units. As long as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found