nodejs v18.12.1 node-gyp v3.6.2 安装node-sass 4.9.0时出现的python2版本不匹配和MSBUILD : error MSB3428报错

一、解决安装node-sass时调用node-gyp找不到python2环境的错误:

vue项目引入sass,node各版本对应node-sass版本_新时代农民工 - 国家级认证的博客-CSDN博客

上面的链接是node-sass和nodejs自带的sass-loader版本匹配关系表,但是对我没啥用,我装的nodejs环境是18.12.1,也不能重新安装nodejs10吧,难道退回10年前?

根据报错:

gyp info using [email protected]
npm ERR! gyp info using [email protected] | win32 | x64
npm ERR! gyp verb command rebuild []
npm ERR! gyp verb command clean []
npm ERR! gyp verb clean removing "build" directory
npm ERR! gyp verb command configure []
npm ERR! gyp verb check python checking for Python executable "python2.7" in the PATH
npm ERR! gyp verb `which` failed Error: not found: python2.7
npm ERR! gyp verb `which` failed     at getNotFoundError (F:\my_download\001components-master\001components-master\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (F:\my_download\001components-master\001components-master\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (F:\my_download\001components-master\001components-master\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at F:\my_download\001components-master\001components-master\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at F:\my_download\001components-master\001components-master\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at F:\my_download\001components-master\001components-master\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:183:21)
npm ERR! gyp verb `which` failed  python2.7 Error: not found: python2.7
npm ERR! gyp verb `which` failed     at getNotFoundError (F:\my_download\001components-master\001components-master\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (F:\my_download\001components-master\001components-master\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (F:\my_download\001components-master\001components-master\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at F:\my_download\001components-master\001components-master\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at F:\my_download\001components-master\001components-master\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:183:21) {
npm ERR! gyp verb `which` failed   code: 'ENOENT'
npm ERR! gyp verb `which` failed }
npm ERR! gyp verb could not find "python2.7". checking python launcher
npm ERR! gyp verb could not find "python2.7". guessing location
npm ERR! gyp verb ensuring that file exists: C:\Python27\python.exe
npm ERR! gyp ERR! stack Error: Can't find Python executable "python2.7", you can set the PYTHON env variable.
npm ERR! gyp ERR! stack     at PythonFinder.failNoPython (F:\my_download\001components-master\001components-master\node_modules\node-gyp\lib\configure.js:484:19)
npm ERR! gyp ERR! stack     at PythonFinder. (F:\my_download\001components-master\001components-master\node_modules\node-gyp\lib\configure.js:509:16)
npm ERR! gyp ERR! stack     at callback (F:\my_download\001components-master\001components-master\node_modules\graceful-fs\polyfills.js:295:20)
npm ERR! gyp ERR! stack     at FSReqCallback.oncomplete (fs.js:183:21)
npm ERR! gyp ERR! System Windows_NT 10.0.18363

查询到相关解决办法,我用的是自己安装python环境的办法。安装包下载地址:Download Python | Python.org

注意安装完配置了windows系统环境变量,因为我的nodejs是18.12.1版本的,应该是默认支持python3以上版本,所以需要配置nodejs环境变量: 

npm config set python python2.7

表示npm中凡是遇到python命令统一修正为执行python2.7,再执行 npm install node-gyp 就报python的错了

解决 node-gyp 错误问题|node与python版本不匹配报错|node-gyp|vue_AKULAKK的博客-CSDN博客

npm解决node-sass python环境问题_Yx0629的博客-CSDN博客

二、解决MSBUILD : error MSB3428报错(node-sass原始资源网站为境外地址,只配置registry=https://registry.npm.taobao.org时,找不到资源,需要单独配置淘宝镜像)

MSBUILD : error MSB3428: 未能加载 Visual C++ 组件“VCBuild.exe”。要解决此问题,1) 安装 .NET Framework 2.0 SDK;2) 安装 Microsoft Visual Studio 2005;或 3) 如果将该组件安 
装到了其他位置,请将其位置添加到系统路径中。

解决方法:

1、在【.npmrc】文件中添加淘宝镜像地址:(然后再重新编译)

phantomjs_cdnurl=http://cnpmjs.org/downloads
sass_binary_site=https://npm.taobao.org/mirrors/node-sass/( 这个是node-sass国内镜像)
registry=https://registry.npm.taobao.org

2、执行卸载安装: npm uninstall node-sass

3、执行重新安装: npm i (我是在vue项目中执行的npm i)
解决MSBUILD : error MSB3428错误_communal的博客-CSDN博客

npm解决node-sass python环境问题_Yx0629的博客-CSDN博客

你可能感兴趣的:(sass,vue.js,javascript)