You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

安装VSC扩展开发依赖yo时执行npm命令报错是什么原因?

问题描述

我在创建新的VS Code扩展时,运行命令npm install -g yo generator-code,报错信息如下:

$ npm install -g yo generator-code
npm WARN npm npm does not support Node.js v15.3.0
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm You can find the latest version at https://nodejs.org/
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@npmcli/arborist@4.0.4',
npm WARN EBADENGINE   required: { node: '^12.13.0 || ^14.15.0 || >=16' },
npm WARN EBADENGINE   current: { node: 'v15.3.0', npm: '8.1.3' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'pacote@12.0.2',
npm WARN EBADENGINE   required: { node: '^12.13.0 || ^14.15.0 || >=16' },
npm WARN EBADENGINE   current: { node: 'v15.3.0', npm: '8.1.3' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@npmcli/map-workspaces@2.0.0',
npm WARN EBADENGINE   required: { node: '^12.13.0 || ^14.15.0 || >=16' },
npm WARN EBADENGINE   current: { node: 'v15.3.0', npm: '8.1.3' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@npmcli/metavuln-calculator@2.0.0',
npm WARN EBADENGINE   required: { node: '^12.13.0 || ^14.15.0 || >=16' },
npm WARN EBADENGINE   current: { node: 'v15.3.0', npm: '8.1.3' }
npm WARN EBADENGINE }
npm notice Beginning October 4, 2021, all connections to the npm registry - including for package installation - must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/
npm notice Beginning October 4, 2021, all connections to the npm registry - including for package installation - must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm ERR! code ENOENT
npm ERR! syscall spawn C:\Program Files (x86)\git\bin\bash.exe
npm ERR! path C:\Users\ARTURALA\npm\node_modules\yo
npm ERR! errno -4058
npm ERR! enoent spawn C:\Program Files (x86)\git\bin\bash.exe ENOENT
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\ARTURALA\scoop\persist\nodejs\cache\_logs\2021-11-12T12_51_46_321Z-debug.log

npm版本:8.1.3
node版本:v15.3.0

问题原因
  • Node版本不兼容:当前使用的Node v15.3.0不属于依赖包支持的版本范围,依赖要求Node版本为12.13.0、14.15.0或者16及以上版本。
  • 缺少Git bash环境:npm无法找到指定路径下的bash.exe文件,要么是未安装Git,要么是Git的执行路径没有添加到系统环境变量。
  • npm源使用HTTP协议:npm官方源要求必须使用HTTPS协议连接,HTTP协议已被弃用,会触发连接异常。
解决方案
  • 更换Node版本,优先选择长期支持的稳定版,比如Node 16.x、18.x及更高的LTS版本,安装完成后重启终端确认版本生效。
  • 安装Git,安装时勾选将Git工具添加到系统环境变量的选项;如果已安装Git,手动把Git安装目录下的bin文件夹路径添加到系统PATH变量,重启终端生效。
  • 执行命令npm config set registry https://registry.npmmirror.com将npm源切换为国内HTTPS镜像源,也可根据需求切换为官方HTTPS源。
  • 所有配置完成后,重新执行npm install -g yo generator-code即可正常安装。

内容的提问来源于stack exchange,提问作者Goaki.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.26 23:45:04