【解决bug之路】npm install node-sass(^4.14.1)连环报错解决!!!(Windows)

有关node-sass的深入分析可参考: 又报gyp ERR!为什么有那么多人被node-sass 坑过?

主要有如下三方面错误,请自查:

1.node,npm版本需与node-sass版本匹配,像node-sass(^4.14.1)就得node 14.x版本才可以,node 16不行

复制代码
gyp ERR! build error
15 gyp ERR! stack Error: `make` failed with exit code: 2
16 gyp ERR! stack     at ChildProcess.onExit (/Users/hongsen.ren/code/bk_cmdb/bk-cmdb/src/ui/node_modules/node-gyp/lib/build.js:262:23)
17 gyp ERR! stack     at ChildProcess.emit (events.js:196:13)
18 gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:256:12)
19 gyp ERR! System Darwin 18.6.0
20 gyp ERR! command "/usr/local/Cellar/node/12.1.0/bin/node" "/Users/hongsen.ren/code/bk_cmdb/bk-cmdb/src/ui/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
21 gyp ERR! cwd /Users/hongsen.ren/code/bk_cmdb/bk-cmdb/src/ui/node_modules/node-sass
22 gyp ERR! node -v v12.1.0
23 gyp ERR! node-gyp -v v3.8.0
24 gyp ERR! not ok

解决方案:可以用nvm切换node或者卸掉原来node再重新安装

查看版本 node -v npm -v

可参考:nvm安装博客https://www.cnblogs.com/rnny/p/17839190.html#:~:text=%E7%9B%AE%E5%BD%95.%20%E3%80%90nvm%E3%80%91%E9%80%82

2.node-sass(^4.14.1)所需python版本对应为2,不是3

PS:网络正常的情况下安装 node-sass 是不需要Python环境的

如果拉不下来对应的binding.node就会进入尝试【本地编译】,然后会检查是否具备的条件:需要python环境,报的错一般就会提示python没有安装

npm ERR! gyp verb find Python - "--python=" or "npm config get python" is "C:\Users\admin\AppData..."

原因:node-sass使用了node-gyp来编译C++代码,而node-gyp需要Python来运行,非得是2也是因为版本对应吗笑死,也没很肯定

解决方案:卸掉原来python3再重新安装python2(记得环境变量也要修改)或者似乎也有python版本管理工具?可自行去查,我没用这个

查看版本 python -v

PS:不过哪怕重新安装了python2,环境变量改成了python2,项目配置python也改成了2,npm install的时候跳出来的地址还是python3的......所以我直接放弃挣扎直接卸载了python3

3.系统缺少Visual C++组件工具"VCBuild.exe"

MSBUILD : error MSB3428: 未能加载 Visual C++ 组件"VCBuild.exe"。要解决此问题,1) 安装 .NET Framework 2.0 SDK;2) 安装 Microso

ft Visual Studio 200

5;或 3) 如果将该组件安装到了其他位置,请将其位置添加到系统路径中。 [E:\mogu-cms-front\node_modules\node-sass\build\binding.sln]

原因:node-sass中引入了 c++ 编写的库

解决方案:用管理员身份打开cmd/PowerShell安装这个c++组件

npm install --global --production windows-build-tools

(要是卡在python安装不动的话,莫慌,说明你需要安装VSStudio的Visual C++生成工具)

具体请参考:

MSBUILD : error MSB3428: 未能加载 Visual C++ 组件"VCBuild.exe"-CSDN博客文章浏览阅读2k次,点赞13次,收藏13次。本文主要解决在运行npm run dev命令时,遇到MSBUILD : error MSB3428: 未能加载 Visual C++ 组件"VCBuild.exe"`错误。_msbuild : error msb3428: 未能加载 visual c++ 组件"vcbuild.exe"。要解决此问https://blog.csdn.net/q1003675852/article/details/135759885

PS:安装太慢的话,试一下换淘宝镜像再用npm安装

npm install --registry=https://registry.npmmirror.com

相关推荐
@大迁世界2 分钟前
TypeScript 的本质并非类型,而是信任
开发语言·前端·javascript·typescript·ecmascript
GIS之路11 分钟前
GDAL 实现矢量裁剪
前端·python·信息可视化
是一个Bug15 分钟前
后端开发者视角的前端开发面试题清单(50道)
前端
Amumu1213816 分钟前
React面向组件编程
开发语言·前端·javascript
持续升级打怪中38 分钟前
Vue3 中虚拟滚动与分页加载的实现原理与实践
前端·性能优化
GIS之路42 分钟前
GDAL 实现矢量合并
前端
hxjhnct44 分钟前
React useContext的缺陷
前端·react.js·前端框架
前端 贾公子1 小时前
从入门到实践:前端 Monorepo 工程化实战(4)
前端
菩提小狗1 小时前
Sqlmap双击运行脚本,双击直接打开。
前端·笔记·安全·web安全
前端工作日常1 小时前
我学习到的AG-UI的概念
前端