简体   繁体   English

VS Code 集成终端抛出`Cannot find module` & `nvm is not compatible with the npm config "prefix" option`

[英]VS Code Integrated Terminal Throws `Cannot find module` & `nvm is not compatible with the npm config "prefix" option`

It looks like this is a fairly common issue, but I've tried everything I can find and still can't seem to resolve it.看起来这是一个相当普遍的问题,但我已经尝试了所有我能找到的东西,但似乎仍然无法解决它。 If I load my terminal outside of VS Code it works fine, but the integrated terminal keeps throwing this when it starts:如果我在 VS Code 之外加载我的终端,它可以正常工作,但是集成终端在启动时会不断抛出这个:

internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module '"/Users/me/Library/Application'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at Module._preloadModules (internal/modules/cjs/loader.js:901:12)
    at preloadModules (internal/bootstrap/node.js:601:7)
    at startup (internal/bootstrap/node.js:273:9)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
nvm is not compatible with the npm config "prefix" option: currently set to ""
Run `nvm use --delete-prefix v10.16.3 --silent` to unset it.

I worked through the steps here , which explain how to remove additional unwanted instances of npm/npx.我完成了此处的步骤,其中解释了如何删除其他不需要的 npm/npx 实例。 The strange thing is that now which npm prints /Users/me/.nvm/versions/node/v10.16.3/bin/npm before the nvm initialization script, which makes it seem like nvm has been loaded properly, but the .zshrc file is being run again, which might be causing the errors.奇怪的是,现在which npmnvm初始化脚本之前打印/Users/me/.nvm/versions/node/v10.16.3/bin/npm ,这使得看起来nvm已经正确加载,但是.zshrc文件正在再次运行,这可能会导致错误。

It looks like there's an extra " in the file path in the error message ( '"/Users/me/Library/Application' ), but I don't see any typos like that in my nvm initialization script, so it seems like maybe it's also a result of the initialization script being called twice?错误消息( '"/Users/me/Library/Application' )中的文件路径中似乎有一个额外的" ,但我在我的nvm初始化脚本中没有看到任何类似的拼写错误,所以看起来可能这也是初始化脚本被调用两次的结果吗?

Something else of note is that node and npm can't be found in the integrated terminal, but they work fine outside of VS Code.其他需要注意的是nodenpm在集成终端中找不到,但它们在 VS Code 之外工作正常。

I've also tried various other things like setting this in my VS Code settings: "terminal.integrated.shellArgs.osx": [] , uninstalling and reinstalling node/nvm both manually and with homebrew.我还尝试了其他各种方法,例如在我的 VS Code 设置中进行设置: "terminal.integrated.shellArgs.osx": [] ,手动和使用自制软件卸载和重新安装 node/nvm。 Any help would be greatly appreciated!任何帮助将不胜感激!

Edit: I tried installing VS Code Insiders and copying over my settings and the integrated terminal loads without any issues.编辑:我尝试安装VS Code Insiders并复制我的设置和集成终端加载,没有任何问题。 So it seems like this might be fixed in a future release.所以看起来这可能会在未来的版本中得到修复。 I'll post an update after the update is available in VS Code to see if this issue goes away.在 VS Code 中提供更新后,我将发布更新,以查看此问题是否消失。

I had this problem and I was just able to fix my issues by disabling auto attaching for debug in the VSCode settings.我遇到了这个问题,我只能通过在 VSCode 设置中禁用自动附加调试来解决我的问题。 Hopefully I can re-enable this in the future since you mentioned there aren't issues with the latest insider release.希望我将来可以重新启用它,因为您提到最新的内部版本没有问题。 I'm using a Bash shell by the way but hopefully this will help you as well.顺便说一句,我正在使用 Bash shell 但希望这也能帮助你。

"debug.node.autoAttach": "disabled",

I tried the accepted solution however it didnt work for me.我尝试了接受的解决方案,但它对我不起作用。

I had to use nvm to uninstall my versions, then just use nvm and install.我必须使用 nvm 卸载我的版本,然后使用 nvm 并安装。 after that I didnt have the error.之后我没有错误。

MacOS version:10.15.6 macOS 版本:10.15.6

  1. $ cd ~ $光盘~
  2. $ touch.zshrc $ touch.zshrc
  3. $ vi.zshrc $ vi.zshrc
export NODE_PATH="/usr/local/lib/node_modules"
  1. $ source.zshrc $ source.zshrc

Try running this command in the Visual Studio Code terminal:尝试在 Visual Studio Code 终端中运行此命令:

nvm use --delete-prefix v12.20.0 --silent

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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