简体   繁体   中英

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

I'm import ing 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:

在此处输入图像描述

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?

在此处输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM