In VScode, how do I open a file from the line it's being imported on?

Viewed 1533

I'm importing various items from a file in vscode. The module exists, but seems to be missing some of the items. I can see the module definitely exists on the filesystem, and vscode even shows me the file name:

enter image description here

I'd like to open the file directly from where it's imported, using the same logic VScode itself uses to import the module. I would have thought right clicking would allow me to do this ('Go to implementation') sounds like it would open the file, but it doesn't do anything.

Obviously I could open a shell and start code pointing to that file, but that's a workaround rather than an actual solution.

How do I open a file being imported in vscode?

enter image description here

2 Answers

There are multiple ways.

  • Right Click and then select "Go to Definition" (not 'go to implementation' as you were using)
  • Select type and then press F12
  • Ctrl (cmd on Mac) + left mouse click

I like the last shortcut. It's easy and reachable.

There is a chance that the module you are viewing is a commonJS module. You could create or add the following settings in .jsonconfig file.

Set/add entry "module": "CommonJS" or set "module": "Node16"

{
  "compilerOptions": {
    "baseUrl": "src",
    "module": "Node16"
  },
  "include": [
    "src"
, "public/src"  ]
}

OR

{
  "compilerOptions": {
    "baseUrl": "src",
    "module": "CommonJS"
  },
  "include": [
    "src"
, "public/src"  ]
}

Hope this helps

Related