In ES6 (like node), importing a module like this
import something from 'something';
Is the same as
import something from 'something/index';
However, vscode appears incapable of performing "Go To Definition" if importing modules using the first method. If I append index
, "Go To Definition" works. Is there a way to modify jsconfig.json
to have vscode check the index
file by default?
I asked this question on github and received this response from Matt Bierner (Microsoft).
Does your project have a jsconfig.json? Can you make sure it contains the setting:
{ "compilerOptions": { "module": "commonjs" } }
Adding the above configuration to my jsconfig.json seems to have fixed the issue even though I'm using ES6 import
and export
syntax.
However this shouldn't be an issue since,
In a jsconfig, the module option only changes how paths are resolved
You can read more about the module
setting here
There is another solution (source). Include the following in your jsconfig:
"compilerOptions": {
"module": "es6",
"moduleResolution": "node"
},
Changing "module": "es6"
to "module": "commonjs"
worked for me too, but I prefer to keep module
set to es6
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With