Windows环境下node-sass安装失败问题

目录

一、环境安装

 二、windows-build-tools依赖安装

三、解决windows-build-tools依赖卡住问题

 四、重新安装node-sass


相信从事vue开发的小伙伴们应该都碰到过sass安装不上的问题,这边详细为大家贴出报错信息,

并给出详细解决方案!

报错信息如下:

npm ERR! code 1
npm ERR! path D:\front_h5\node_modules\node-sass
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node scripts/build.js
npm ERR! Building: F:\nodejs\node.exe D:\front_h5\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp verb cli [
npm ERR! gyp verb cli   'F:\\nodejs\\node.exe',
npm ERR! gyp verb cli   'D:\\front_h5\\node_modules\\node-gyp\\bin\\node-gyp.js',
npm ERR! gyp verb cli   'rebuild',
npm ERR! gyp verb cli   '--verbose',
npm ERR! gyp verb cli   '--libsass_ext=',
npm ERR! gyp verb cli   '--libsass_cflags=',
npm ERR! gyp verb cli   '--libsass_ldflags=',
npm ERR! gyp verb cli   '--libsass_library='
npm ERR! gyp verb cli ]
npm ERR! 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" in the PATH
npm ERR! gyp verb `which` failed Error: not found: python2
npm ERR! gyp verb `which` failed     at getNotFoundError (D:\front_h5\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (D:\front_h5\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (D:\front_h5\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at D:\front_h5\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at D:\front_h5\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at D:\front_h5\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21)
npm ERR! gyp verb `which` failed  python2 Error: not found: python2
npm ERR! gyp verb `which` failed     at getNotFoundError (D:\front_h5\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (D:\front_h5\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (D:\front_h5\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at D:\front_h5\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at D:\front_h5\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at D:\front_h5\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21) {
npm ERR! gyp verb `which` failed   code: 'ENOENT'
npm ERR! gyp verb `which` failed }
npm ERR! gyp verb check python checking for Python executable "python" in the PATH
npm ERR! gyp verb `which` failed Error: not found: python
npm ERR! gyp verb `which` failed     at getNotFoundError (D:\front_h5\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (D:\front_h5\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (D:\front_h5\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at D:\front_h5\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at D:\front_h5\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at D:\front_h5\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21)
npm ERR! gyp verb `which` failed  python Error: not found: python
npm ERR! gyp verb `which` failed     at getNotFoundError (D:\front_h5\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (D:\front_h5\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (D:\front_h5\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at D:\front_h5\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at D:\front_h5\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at D:\front_h5\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21) {
npm ERR! gyp verb `which` failed   code: 'ENOENT'
npm ERR! gyp verb `which` failed }
npm ERR! gyp verb could not find "python". checking python launcher
npm ERR! gyp verb could not find "python". guessing location
npm ERR! gyp verb ensuring that file exists: C:\Python27\python.exe
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
npm ERR! gyp ERR! stack     at PythonFinder.failNoPython (D:\front_h5\node_modules\node-gyp\lib\configure.js:484:19)
npm ERR! gyp ERR! stack     at PythonFinder. (D:\front_h5\node_modules\node-gyp\lib\configure.js:509:16)
npm ERR! gyp ERR! stack     at callback (D:\front_h5\node_modules\graceful-fs\polyfills.js:306:20)
npm ERR! gyp ERR! stack     at FSReqCallback.oncomplete (node:fs:198:21)
npm ERR! gyp ERR! System Windows_NT 10.0.22000
npm ERR! gyp ERR! command "F:\\nodejs\\node.exe" "D:\\front_h5\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
npm ERR! gyp ERR! cwd D:\front_h5\node_modules\node-sass
npm ERR! gyp ERR! node -v v16.16.0
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok
npm ERR! Build failed with error code: 1

这是因为我们电脑本地环境缺失所导致的安装失败问题。

一、环境安装

所需要的环境为

node  v16.16.0
npm   8.11.0

Python 2.7.15

python下载地址:https://www.python.org/ftp/python/2.7.15/python-2.7.15.amd64.msi

node下载地址:https://nodejs.org/download/release/v16.16.0/node-v16.16.0-x64.msi

node环境安装此处不再赘述,看下python的环境安装步骤

Windows环境下node-sass安装失败问题_第1张图片Windows环境下node-sass安装失败问题_第2张图片

安装完毕后验证python版本

PS C:\WINDOWS\system32> python -V
Python 2.7.15

 二、windows-build-tools依赖安装

windows-build-tools安装一般都会卡住,这是因为这个依赖的脚本本身有问题。这个问题在github

的issue中可以找到相关描述:

链接:https://github.com/felixrieseberg/windows-build-tools/issues/244

安装命令如下:

npm install --global windows-build-tools

 通常会卡在如图位置:

Windows环境下node-sass安装失败问题_第3张图片

三、解决windows-build-tools依赖卡住问题

 解决步骤如下:
1、在用户temp文件夹下找到最新的dd_installer_xxx.log文件

Windows环境下node-sass安装失败问题_第4张图片
2、查看此文件内容,确保日志输出了Closing the installer with exit code 0

Windows环境下node-sass安装失败问题_第5张图片
3、用vscode打开你本地的temp文件夹,并在目录下创建一个dd_client_.log文件

Windows环境下node-sass安装失败问题_第6张图片
4、在dd_client_.log文件中添加

Closing installer. Return code: 3010.

并ctrl+s保存。

5、重新运行npm install --global windows-build-tools命令便可以顺利安装成功!
Windows环境下node-sass安装失败问题_第7张图片

 四、重新安装node-sass

 重新运行npm install node-sass --save命令

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