- 问题描述
笔者的测试环境如下:
操作系统:Windows 11
Node版本:v14.21.3
Npm版本:6.14.18
遇到的node-sass安装失败的报错如下:
PS E:\VScodeSpace\maintain-main-recommend> npm install node-sass@^4.14.0
npm WARN deprecated node-sass@4.14.0: Node Sass is no longer supported. Please use `sass` or `sass-embedded` instead.
npm WARN deprecated npmlog@4.1.2: This package is no longer supported.
npm WARN deprecated fstream@1.0.12: This package is no longer supported.
npm WARN deprecated osenv@0.1.5: This package is no longer supported.
npm WARN deprecated tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.
npm WARN deprecated are-we-there-yet@1.1.7: This package is no longer supported.
npm WARN deprecated gauge@2.7.4: This package is no longer supported.
> node-sass@4.14.0 install E:\VScodeSpace\maintain-main-recommend\node_modules\node-sass
> node scripts/install.js
Downloading binary from https://github.com/sass/node-sass/releases/download/v4.14.0/win32-x64-83_binding.node
Cannot download "https://github.com/sass/node-sass/releases/download/v4.14.0/win32-x64-83_binding.node":
read ECONNRESET
Hint: If github.com is not accessible in your location
try setting a proxy via HTTP_PROXY, e.g.
export HTTP_PROXY=http://example.com:1234
or configure npm proxy via
npm config set proxy http://example.com:8080
> node-sass@4.14.0 postinstall E:\VScodeSpace\maintain-main-recommend\node_modules\node-sass
> node scripts/build.js
Building: D:\EVM\nodejs\node.exe E:\VScodeSpace\maintain-main-recommend\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
gyp info it worked if it ends with ok
gyp verb cli [
gyp verb cli 'D:\\EVM\\nodejs\\node.exe',
gyp verb cli 'E:\\VScodeSpace\\maintain-main-recommend\\node_modules\\node-gyp\\bin\\node-gyp.js',
gyp verb cli 'rebuild',
gyp verb cli '--verbose',
gyp verb cli '--libsass_ext=',
gyp verb cli '--libsass_cflags=',
gyp verb cli '--libsass_ldflags=',
gyp verb cli '--libsass_library='
gyp verb cli ]
gyp info using node-gyp@3.8.0
gyp info using node@14.21.3 | win32 | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` failed Error: not found: python2
gyp verb `which` failed at getNotFoundError (E:\VScodeSpace\maintain-main-recommend\node_modules\which\which.js:13:12)
gyp verb `which` failed at F (E:\VScodeSpace\maintain-main-recommend\node_modules\which\which.js:68:19)
gyp verb `which` failed at E (E:\VScodeSpace\maintain-main-recommend\node_modules\which\which.js:80:29)
gyp verb `which` failed at E:\VScodeSpace\maintain-main-recommend\node_modules\which\which.js:89:16
gyp verb `which` failed at E:\VScodeSpace\maintain-main-recommend\node_modules\isexe\index.js:42:5
gyp verb `which` failed at E:\VScodeSpace\maintain-main-recommend\node_modules\isexe\windows.js:36:5
gyp verb `which` failed at FSReqCallback.oncomplete (fs.js:192:21)
gyp verb `which` failed python2 Error: not found: python2
gyp verb `which` failed at getNotFoundError (E:\VScodeSpace\maintain-main-recommend\node_modules\which\which.js:13:12)
gyp verb `which` failed at F (E:\VScodeSpace\maintain-main-recommend\node_modules\which\which.js:68:19)
gyp verb `which` failed at E (E:\VScodeSpace\maintain-main-recommend\node_modules\which\which.js:80:29)
gyp verb `which` failed at E:\VScodeSpace\maintain-main-recommend\node_modules\which\which.js:89:16
gyp verb `which` failed at E:\VScodeSpace\maintain-main-recommend\node_modules\isexe\index.js:42:5
gyp verb `which` failed at E:\VScodeSpace\maintain-main-recommend\node_modules\isexe\windows.js:36:5
gyp verb `which` failed at FSReqCallback.oncomplete (fs.js:192:21) {
gyp verb `which` failed code: 'ENOENT'
gyp verb `which` failed }
gyp verb check python checking for Python executable "python" in the PATH
gyp verb `which` failed Error: not found: python
gyp verb `which` failed at getNotFoundError (E:\VScodeSpace\maintain-main-recommend\node_modules\which\which.js:13:12)
gyp verb `which` failed at F (E:\VScodeSpace\maintain-main-recommend\node_modules\which\which.js:68:19)
gyp verb `which` failed at E (E:\VScodeSpace\maintain-main-recommend\node_modules\which\which.js:80:29)
gyp verb `which` failed at E:\VScodeSpace\maintain-main-recommend\node_modules\which\which.js:89:16
gyp verb `which` failed at E:\VScodeSpace\maintain-main-recommend\node_modules\isexe\index.js:42:5
gyp verb `which` failed at E:\VScodeSpace\maintain-main-recommend\node_modules\isexe\windows.js:36:5
gyp verb `which` failed at FSReqCallback.oncomplete (fs.js:192:21)
gyp verb `which` failed python Error: not found: python
gyp verb `which` failed at getNotFoundError (E:\VScodeSpace\maintain-main-recommend\node_modules\which\which.js:13:12)
gyp verb `which` failed at F (E:\VScodeSpace\maintain-main-recommend\node_modules\which\which.js:68:19)
gyp verb `which` failed at E (E:\VScodeSpace\maintain-main-recommend\node_modules\which\which.js:80:29)
gyp verb `which` failed at E:\VScodeSpace\maintain-main-recommend\node_modules\which\which.js:89:16
gyp verb `which` failed at E:\VScodeSpace\maintain-main-recommend\node_modules\isexe\index.js:42:5
gyp verb `which` failed at E:\VScodeSpace\maintain-main-recommend\node_modules\isexe\windows.js:36:5
gyp verb `which` failed at FSReqCallback.oncomplete (fs.js:192:21) {
gyp verb `which` failed code: 'ENOENT'
gyp verb `which` failed }
gyp verb could not find "python". checking python launcher
gyp verb could not find "python". guessing location
gyp verb ensuring that file exists: C:\Python27\python.exe
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
gyp ERR! stack at PythonFinder.failNoPython (E:\VScodeSpace\maintain-main-recommend\node_modules\node-gyp\lib\configure.js:484:19)
gyp ERR! stack at PythonFinder.<anonymous> (E:\VScodeSpace\maintain-main-recommend\node_modules\node-gyp\lib\configure.js:509:16)
gyp ERR! stack at callback (E:\VScodeSpace\maintain-main-recommend\node_modules\graceful-fs\polyfills.js:295:20)
gyp ERR! stack at FSReqCallback.oncomplete (fs.js:192:21)
gyp ERR! System Windows_NT 10.0.22631
gyp ERR! command "D:\\EVM\\nodejs\\node.exe" "E:\\VScodeSpace\\maintain-main-recommend\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd E:\VScodeSpace\maintain-main-recommend\node_modules\node-sass
gyp ERR! node -v v14.21.3
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
Build failed with error code: 1
npm WARN @wangeditor/editor-for-vue@1.0.2 requires a peer of vue@^2.6.14 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules\webpack\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@4.14.0 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@4.14.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! D:\EVM\node14\node_cache\_logs\2025-04-08T02_10_40_414Z-debug.log
报错截图:
- 解决方案
- 检查node-sass安装版本是否正确。
本地安装的node版本不同,需要安装的node-sass版本也是不一样的。node-sass官方给出了不同版本的node和node-sass的对应关系,读者可访问node-sass npm仓库进行查看。
本地安装的node版本,可以使用如下命令进行查看:
node -v
下图为版本对应关系
在项目中还没有package.json或者有package.json但是此文件指定node-sass的版本与自己node版本不对应时,才有了前文中报错。
根据版本对应关系,笔者应该安装node-sass的4.14+版本,因此需要将安装命令改为:
npm install node-sass@^4.14.0 --registry=https://registry.npmmirror.com
这样就是使用淘宝源来安装node-sass的4.14+中的最新版本。
- 检查是否是网络问题
在使用npm install安装node-sass时,会从 github.com 上下载 .node 文件。由于国内网络环境的问题,这个下载时间可能会很长,甚至导致超时失败。
npm install node-sass@^4.14.0 --registry=https://registry.npmmirror.com --sass_binary_site=https://www.npmmirror.com/mirrors/node-sass/
这样一来就是指定node-sass版本,指定npm包下载源为淘宝源,指定sass下载源为淘宝源,使用此命令基本就都能安装成功了。