node-sass安装失败简单解决方案

问题

安装node-sass遇到了如下错误

PS E:\phoneEmall\phone-emall> npm i node-sass

> node-sass@3.13.1 install E:\phoneEmall\phone-emall\node_modules\node-sass
> node scripts/install.js

Downloading binary from https://github.com/sass/node-sass/releases/download/v3.13.1/win32-x64-64_binding.node
Cannot download "https://github.com/sass/node-sass/releases/download/v3.13.1/win32-x64-64_binding.node":

HTTP error 404 Not Found

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@3.13.1 postinstall E:\phoneEmall\phone-emall\node_modules\node-sass
> node scripts/build.js

Building: C:\Program Files\nodejs\node.exe E:\phoneEmall\phone-emall\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 [ 'C:\\Program Files\\nodejs\\node.exe',
gyp verb cli   'E:\\phoneEmall\\phone-emall\\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 info using node-gyp@3.8.0
gyp info using node@10.15.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:\phoneEmall\phone-emall\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (E:\phoneEmall\phone-emall\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (E:\phoneEmall\phone-emall\node_modules\which\which.js:80:29)
gyp verb `which` failed     at E:\phoneEmall\phone-emall\node_modules\which\which.js:89:16
gyp verb `which` failed     at E:\phoneEmall\phone-emall\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at E:\phoneEmall\phone-emall\node_modules\isexe\windows.js:36:5
gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:153:21)
gyp verb `which` failed  python2 { Error: not found: python2
gyp verb `which` failed     at getNotFoundError (E:\phoneEmall\phone-emall\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (E:\phoneEmall\phone-emall\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (E:\phoneEmall\phone-emall\node_modules\which\which.js:80:29)
gyp verb `which` failed     at E:\phoneEmall\phone-emall\node_modules\which\which.js:89:16
gyp verb `which` failed     at E:\phoneEmall\phone-emall\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at E:\phoneEmall\phone-emall\node_modules\isexe\windows.js:36:5
gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:153:21)
gyp verb `which` failed   stack:
gyp verb `which` failed    'Error: not found: python2\n    at getNotFoundError (E:\\phoneEmall\\phone-emall\\node_modules\\which\\which.js:13:12)\n    at F (E:\\phoneEmall\\phone-emall\\node_modules\\which\\which.js:68:19)\n    at E (E:\\phoneEmall\\phone-emall\\node_modules\\which\\which.js:80:29)\n    at E:\\phoneEmall\\phone-emall\\node_modules\\which\\which.js:89:16\n    at E:\\phoneEmall\\phone-emall\\node_modules\\isexe\\index.js:42:5\n    at E:\\phoneEmall\\phone-emall\\node_modules\\isexe\\windows.js:36:5\n    at FSReqWrap.oncomplete (fs.js:153:21)',
gyp verb `which` failed   code: 'ENOENT' }
gyp verb check python checking for Python executable "python" in the PATH
gyp verb `which` succeeded python C:\Users\Administrator\AppData\Local\Programs\Python\Python37\python.EXE
gyp ERR! configure error
gyp ERR! stack Error: Command failed: C:\Users\Administrator\AppData\Local\Programs\Python\Python37\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack   File "<string>", line 1
gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack                                ^
gyp ERR! stack SyntaxError: invalid syntax
gyp ERR! stack
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:294:12)
gyp ERR! stack     at ChildProcess.emit (events.js:189:13)
gyp ERR! stack     at maybeClose (internal/child_process.js:970:16)
gyp ERR! stack     at Socket.stream.socket.on (internal/child_process.js:389:11)
gyp ERR! stack     at Socket.emit (events.js:189:13)
gyp ERR! stack     at Pipe._handle.close (net.js:597:12)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "E:\\phoneEmall\\phone-emall\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd E:\phoneEmall\phone-emall\node_modules\node-sass
gyp ERR! node -v v10.15.3
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
Build failed with error code: 1
npm WARN sass-loader@3.2.3 requires a peer of webpack@^1.12.6 || ^2.1.0-beta but none is installed. You must install peer dependencies yourself.
npm WARN webpack-dev-middleware@1.12.2 requires a peer of webpack@^1.0.0 || ^2.0.0 || ^3.0.0 but
none is installed. You must install peer dependencies yourself.
npm WARN webpack-dev-server@1.16.5 requires a peer of webpack@>=1.3.0 <3 but none is installed. You must install peer dependencies yourself.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@3.13.1 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@3.13.1 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!     C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2019-07-12T03_34_51_589Z-debug.log

找答案

看着这报错信息,看到有文件下载出现404,然后我又去找文件,结果搞hosts文件,我以为是python问题,然后重装各种版本python…

花了3小时,试了网上无数种答案,没有可以解决的

解决方案

将sass-loader和node-sass的版本号提高到最新版,目前的最新版如下(2019年7月12日)
“sass-loader”: “^7.1.0”,
“node-sass”: “^4.12.0”,

如图所示,把package.json文件修改一下
在这里插入图片描述

然后再执行如下命令安装

npm i sass-loader
npm i node-sass

2020-05-06更新

这个问题出现的原因往往是 Node-sass 的版本问题,可能的一个原因是:因为版本太老所以会导致有的依赖项已经找不到了,公司有一个4年前的老项目就是这种问题,上面修改Node-sass的版本为4.12并不一定适合所有项目,可以多测试几个版本,如果上面的版本失败了可以试一试这个版本

"node-sass": "^4.13.1",
"sass-loader": "^4.1.1",

2021-06-06更新

Nodejs版本切换为13.6,这样才可以匹配上node sass的版本
简单的方法是,先卸载nodejs,然后安装13.6版本的
Nodejs13.6版本官网下载

仍然失败怎么办?

我的答案并不一定适合你,但是你要相信柳暗花明又一村。

一个热心探讨程序+理财的人,欢迎交流~

lianggelicai666

在这里插入图片描述

评论 18
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

冰奕辰

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

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

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

打赏作者

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

抵扣说明:

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

余额充值