Vue项目npm install报错gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8

问题描述:

整理了几乎网上所有的解决办法,全网最全,含泪解决

 前端Vue项目,之前运行都没问题,node_modules删掉后,重新npm install报错,报错如下:

gyp ERR! find VS
gyp ERR! find VS msvs_version not set from command line or npm config
gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details
gyp ERR! find VS looking for Visual Studio 2015
gyp ERR! find VS - not found
gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
gyp ERR! find VS
gyp ERR! find VS **************************************************************
gyp ERR! find VS You need to install the latest version of Visual Studio
gyp ERR! find VS including the "Desktop development with C++" workload.
gyp ERR! find VS For more information consult the documentation at:
gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
gyp ERR! find VS **************************************************************
gyp ERR! find VS
gyp ERR! configure error
gyp ERR! stack Error: Could not find any Visual Studio installation to use
gyp ERR! stack     at VisualStudioFinder.fail (D:\workspace\dscp\node_modules\node-gyp\lib\find-visualstudio.js:122:47)
gyp ERR! stack     at D:\workspace\dscp\node_modules\node-gyp\lib\find-visualstudio.js:75:16
gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (D:\workspace\dscp\node_modules\node-gyp\lib\find-visualstudio.js:363:14)
gyp ERR! stack     at D:\workspace\dscp\node_modules\node-gyp\lib\find-visualstudio.js:71:14
gyp ERR! stack     at D:\workspace\dscp\node_modules\node-gyp\lib\find-visualstudio.js:384:16
gyp ERR! stack     at D:\workspace\dscp\node_modules\node-gyp\lib\util.js:54:7
gyp ERR! stack     at D:\workspace\dscp\node_modules\node-gyp\lib\util.js:33:16
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:390:5)
gyp ERR! stack     at ChildProcess.emit (events.js:400:28)
gyp ERR! stack     at maybeClose (internal/child_process.js:1088:16)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:296:5)
gyp ERR! System Windows_NT 10.0.22621
gyp ERR! command "D:\\Program Files\\nodejs\\node.exe" "D:\\workspace\\dscp\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd D:\workspace\dscp\node_modules\node-sass
gyp ERR! node -v v14.21.3
gyp ERR! node-gyp -v v8.4.1
gyp ERR! not ok

解决方案一:

可能原因为nodejs版本问题,我原版本为v16.20.1,卸载后重新安装v14.21.3。

解决方案二:

nodejs与node-sass版本不匹配导致。

查看node版本:node -v

根据node版本与node-sass版本对应关系修改package.json文件node-sass版本,修改sass-loader版本

node与node-sass版本对应表
node版本 node-sass版本
node 16——6.0+
node 15——5.0+
node 14——4.14+
node13—— 4.13+,<5.0
node12—— 4.12+
node11—— 4.10+,<5.0
node10—— 4.9+,<5.0
node8——4.5.3+,<5.0
node<8—— <5.0

sass-loader与node-sass版本对应表
sass-loader版本 node-sass版本
sass-loader 4.1.1—— node-sass 4.3.0
sass-loader 7.0.3—— node-sass 4.7.2
sass-loader 7.3.1—— node-sass 4.7.2
sass-loader 7.3.1—— node-sass 4.14.1
sass-loader 10.0.1—— node-sass 6.0.1

 解决方案三:

node-sass版本问题,管理员权限下在终端执行。

npm config set sass_binary_site=https://npm.taobao.org/mirrors/node-sass
npm install --save

 解决方案四:

重新安装nodejs,安装完直接下载CNPM淘宝镜像)进行安装CNPM安装办法:

npm install -g cnpm -registry=https://registry.npm.taobao.org

查看cnpm是否真安装成功:

cnpm -v

 解决方案五:

npm环境中gyp配置有问题,需要安装gyp和Windows构建工具windows-build-tools,以管理员身份运行以下命令。

npm install -g node-gyp
npm install --global --production windows-build-tools

 解决方案六:

网上有说因为本地安装了python3版本的原因,并且设置了环境变量,所以npm install会找我默认的python,所以执行时指定nodejs只支持的python2版本。

我本地的确安装了Python 3.11.3,接下来按以下步骤操作。

1、卸载nodejs,重新安装一遍

2、设置淘宝镜像

npm config set registry https://registry.npm.taobao.org

3、安装nodejs所需的环境,执行这个命令会自动检测并帮你安装好

npm install --g --production windows-build-tools

4、关键

执行编译时指定python2.7版本

​npm install --python=python2.7

 解决方案七:

原因为依赖冲突,执行命令如下

1、清除缓存 

npm cache clean --force

2、执行命令

npm install --legacy-peer-deps

 npm install --legacy-peer-deps命令与其说是告诉npm要去干什么,不如说是告诉npm不要去干什么。

legacy的意思:遗产/(软件或硬件)已过时但因使用范围广而难以替代的;而npm install xxxx --legacy-peer-deps命令用于绕过peerDependency里依赖的自动安装;它告诉npm忽略项目中引入的各个依赖模块之间依赖相同但版本不同的问题,以npm v3-v6的方式去继续执行安装操作。

所以其实该命令并没有真的解决冲突,而是忽略了冲突,以“过时”(v3-v6)的方式进行下载操作。

  • 10
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Gzzz__

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值