微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用纱线运行构建系统的 Volta 找不到指定的路径

如何解决使用纱线运行构建系统的 Volta 找不到指定的路径

这是我第一次使用 Volta,请耐心等待。

我已经全局安装了 typescript、node 和 yarn

yarn -v >> 1.22.10
node -v >> v14.15.4
npm -v >> 6.14.10

这些命令在我的项目文件夹内外都有效,结果相同。 但是,如果我从 vscode 内部使用 yarn build 输出一个错误说明: System cannot find the path specified

System cannot find the path specified

如果我从外部 vscode 做同样的事情,我会得到相同的结果:

System cannot find the path specified

如果我转到 vscode 中的 node_modules/.bin 文件夹,该命令仍然不起作用(这次我只运行了 tsc)。错误如下:

The term tsc is not a cmdlet recognized command,function,script file or executable program. Verify if the name is written correctly or,if there is an access route,verify the route is correct and try again.

The term tsc is not a cmdlet recognized command,verify the route is correct and try again.

但是如果在 cmd 窗口中从 vscode 外部执行命令,它会按预期工作,因为 tsc 确实存在:

tsc is working

此外,如果我在 vscode 中运行 npm run build,该命令会按预期工作。这是我的 package.json:

{
  "name": "socket-server","version": "1.0.0","main": "dist/index.js","types": "dist/index.d.ts","license": "MIT","scripts": {
    "build": "tsc","dev": "yarn build --watch --preserveWatchOutput","lint": "eslint src --ext js,ts","test": "jest"
  },"devDependencies": {
    "eslint": "^7.19.0","jest": "^26.6.3","typescript": "^4.1.3"
  },"volta": {
    "node": "14.15.4","yarn": "1.22.10"
  }
}

我确实怀疑 volta,因为 volta 正在管理纱线版本,但没有 npm;但我真的不知道这是什么问题。

我使用的是 Windows,我的 PATH 有以下条目:

Volta and npm paths are present on my user folder

我做错了什么?

编辑:是的,Shell 命令快捷方式存在:

Shell command shortcut

解决方法

问题是关于 vsCode,你应该在 code . 中运行 cmd 因为如果你打开命令面板 (Ctrl + Shift + P) 并输入

Shell Command: Install 'code' command in PATH

你不会看到提示,当你应该看到这张照片时,在cmd中运行code .后,一切都会好起来

enter image description here

,

我不确定是否适用于 Windows,但通常 node_modules/.bin 中的脚本是脚本的符号链接。例如,node_modules/.bin/tsc 可能指向 node_modules/typescript/bin/tsc

它在目录之外工作,因为它使用全球版本的 tsc

看到您的错误,我怀疑符号链接已损坏。也许只是尝试删除 node_modules 目录并重做 npm install

PS:我不熟悉 Volta,但它看起来更像是 NPM 问题。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。