Vscode: Go to definition doesn't work for ES6 imports when omitting `index` from the path.

Created on 13 Apr 2017  路  3Comments  路  Source: microsoft/vscode

  • VSCode Version: 1.12.0-insider
  • OS Version: Windows 7
  • Commit d1b315f03013b72d0fbb0a5c8ccc08088de315eb
  • Date 2017-04-13T06:10:58.128Z
  • Shell 1.6.6
  • Renderer 56.0.2924.87
  • Node 7.4.0

Steps to Reproduce:

Code

import { member } from './myModule'

Directory Structure: ./myModule/index.js

  1. Right click on member
  2. Click "Go to definition"
  3. The message, "No definition found for 'member'" appears.
  4. Update code to:
import { member } from './myModule/index'
  1. "Go to definition" now works as expected.

gotodefinition

I'm not sure if this is a vscode or a TypeScript specific issue (my understanding is that the TypeScript engine is powering all JS intellisense). Perhaps it can be resolved using some settings in jsconfig.json? Apologize if it's configuration based, but I couldn't find anything in the docs.

The docs on TypeScript's module resolution seem to suggest that this should work without having to explicitly mention the index file in the path: https://www.typescriptlang.org/docs/handbook/module-resolution.html

*question javascript typescript

Most helpful comment

Does your project have a jsconfig.json? Can you make sure it contains the setting:

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

All 3 comments

Does your project have a jsconfig.json? Can you make sure it contains the setting:

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

That worked! Does it matter that I'm using ES6 import and export syntax?

Not in this case since you are working with JavaScript instead of TypeScript. In a jsconfig, the module option only changes how paths are resolved

Was this page helpful?
0 / 5 - 0 ratings