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

问题

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

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

> [email protected] 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

> [email protected] 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 [email protected]
gyp info using [email protected] | 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 "", 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 [email protected] requires a peer of webpack@^1.12.6 || ^2.1.0-beta but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] 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 [email protected] 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! [email protected] postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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文件修改一下
node-sass安装失败简单解决方案_第1张图片

然后再执行如下命令安装

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",

仍然失败怎么办?

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

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

node-sass安装失败简单解决方案_第2张图片

你可能感兴趣的:(问题合集)