Richard Szalay
Richard Szalay

Reputation: 84724

VSCode import node modules with relative paths

I've somehow gotten my workspace into a state where VSCode is offering to add imports for node modules using the relative path to the module's @types:

VSCode offering to import 'React' from '../../../../node_modules/@types/react' rather than 'react'

It started when we added paths (as described here), but reverting those changes doesn't seem to help (even after a "Reload TS Project" or even reload of VS Code).

Any thoughts on what might be causing this?

VSCode's "Import Module Specifier" is set to auto

Upvotes: 4

Views: 4542

Answers (1)

Asa Hardcastle
Asa Hardcastle

Reputation: 56

If your workspace is using Typescript 2.9.2 then it may be this issue:

https://github.com/Microsoft/vscode/issues/53597

You can see the version of typescript in the lower right bottom bar. If you click on it, you will see the versions of TS that you already have available to you.

see the typescript version

The suggested workaround is to downgrade the version of TypeScript that your workspace uses to 2.7.2. or to upgrade to typescript@next

The Microsoft engineer that closed this bug stated:

This has been fixed in VS Code insiders. On the current version of VS Code, you can also upgrade your workspace to use Typescript 3.0. We did not backport the fix due to lack of testing, engineering cost, and concerns about causing other regressions.

Also, I have tested installing both 2.7.2 and typescript@next into my local node_modules. Both solve the problem.

I hope this helps!

Upvotes: 4

Related Questions