Go to the definition for ES6 import if index.js is omitted

In ES6 (e.g. node), importing a module like this

import something from 'something';

Same as

import something from 'something/index';

However, vscode seems unable to execute "Go to Definition" when importing modules using the first method. If I add index , "Go to definition" works. Is there a way to modify jsconfig.json so that vscode checks the default index file?

+6
source share
1 answer

I asked this question on github and received this answer from Matt Bierner (Microsoft).

Is there jsconfig.json in your project? Can you make sure that it contains the setting:

{ "compilerOptions": { "module": "commonjs" } }

Adding the above configuration to my jsconfig.json seems to fix the problem, although I am using ES6 import and export .

However, this should not be a problem since

In jsconfig, the module parameter only changes the path elimination paths

Here you can find out more about module

+10
source

Source: https://habr.com/ru/post/1014933/


All Articles