搭建vue项目时下载node-sass依赖包,会出现如下错误:
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "C:\Users\zhuon\AppData\Local\Programs\Python\Python36\python.EXE", you can set the PYTHON env variable.
gyp ERR! stack at PythonFinder.failNoPython (G:\Workspace\ManYan\manyan-nav\node_modules\node-gyp\lib\configure.js:483:19)
gyp ERR! stack at PythonFinder.<anonymous> (G:\Workspace\ManYan\manyan-nav\node_modules\node-gyp\lib\configure.js:508:16)
gyp ERR! stack at G:\Workspace\ManYan\manyan-nav\node_modules\graceful-fs\polyfills.js:284:29
gyp ERR! stack at FSReqWrap.oncomplete (fs.js:152:21)
gyp ERR! System Windows_NT 10.0.15063
gyp ERR! command "C:\\dev\\nodejs\\node.exe" "G:\\Workspace\\ManYan\\manyan-nav\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags="
"--libsass_library="
gyp ERR! cwd G:\Workspace\ManYan\manyan-nav\node_modules\node-sass
gyp ERR! node -v v8.4.0
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
Build failed
npm WARN co-mocha@1.2.0 requires a peer of mocha@>=1.18 <4 but none was installed.
npm WARN egg-restapi-module-tool@1.0.0 No repository field.
npm WARN egg-restapi-module-tool@1.0.0 scripts['server'] should probably be scripts['start'].
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@3.8.0 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@3.8.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:\nodejs\cache\_logs\2017-09-02T16_06_24_298Z-debug.log
解决办法一:
复制这个:https://github.com/sass/node-sass/releases/download/v4.9.4/win32-x64-57_binding.node 到浏览器去下载,该地址详见你的控制台相关信息,该文件2.4M左右,下载完之后配置环境变量
重启电脑:
win+R cmd 输入:echo空格%SASS_BINARY_PATH%
然后安装node-sass即可:
感谢@kevin_LL提供帮助
解决办法二:
下载项目的时候run install时,node-sass下载失败后来我在项目根目录下添加了一个.npmrc
sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
registry=https://registry.npm.taobao.org
把node-sass的路径修改成淘宝的npm,就很顺利的可以在国内的网络环境下载了
总结:两种方法各有利弊,方法一,只要该电脑配置过此环境变量,则以后任何项目需要 install 的项目下载都很顺利。但是配置过于繁琐。方法二:新增一个文件即可,配置简单,但是每个项目都需要加一个配置文件。