报错信息

gyp verb command build []
gyp verb build type Release
gyp verb architecture x64
gyp verb node dev dir C:\Users\XXX\.node-gyp\10.15.0
gyp verb found first Solution file build/binding.sln
gyp verb could not find "msbuild.exe" in PATH - finding location in registry
gyp ERR! build error
gyp ERR! stack Error: Command failed: C:\Windows\System32\reg.exe query "HKLM\Software\Microsoft\MSBuild\ToolsVersions" /s /reg:32
gyp ERR! stack ����: ע����༭������Ա���á�
gyp ERR! stack
gyp ERR! stack Can't find "msbuild.exe". Do you have Microsoft Visual Studio C++ 2008+ installed?
gyp ERR! stack     at D:\DayDayUp\testpro\testpro-admin\node_modules\node-gyp\lib\build.js:142:25
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:301:5)
gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
gyp ERR! stack     at maybeClose (internal/child_process.js:962:16)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "D:\\nodejs\\node.exe" "D:\\DayDayUp\\testpro\\testpro-admin\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd D:\DayDayUp\testpro\testpro-admin\node_modules\node-sass
gyp ERR! node -v v10.15.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
Build failed with error code: 1
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.7 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@4.11.0 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@4.11.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\node_cache\_logs\2019-02-26T01_59_23_671Z-debug.log

提取关键信息:
gyp verb could not find “msbuild.exe” in PATH - finding location in registry
gyp ERR! stack Can’t find “msbuild.exe”. Do you have Microsoft Visual Studio C++ 2008+ installed?


带来的思考

  • 这日志从哪里打印出来的

经过分析发现,该日志是node-gyp包的build.js打印出来的,该文件路径为{YOUR DIR}\node_modules\node-gyp\lib。网上针对该问题是修改build.js文件,如下:

var cmd = 'reg.exe query "HKLM\\Software\\Microsoft\\MSBuild\\ToolsVersions" /s'
改为
var cmd = 'C:\\Windows\\System32\\reg.exe query "HKLM\\Software\\Microsoft\\MSBuild\\ToolsVersions" /s'

然而,我试了下,没有解决问题!!!

  • 既然npm安装不了node-sass,那我们换cnpm是否可以

于是我就尝试安装cnpm,再用cnpm安装node-sass,命令如下:

$ npm install -g cnpm
$ cnpm install -g node-sass

竟然没有报错有没有!!!,于是我们思考一下,npm与cnpm的安装区别到底在哪里,是下载的源不一样,还是实现安装逻辑不一样?

  • 我们给npm换源试一试?

我们都知道怎么给npm换taobao源,但是我们没有给sass单独设置过数据源,说做就做:

$ npm config set sass-binary-site http://npm.taobao.org/mirrors/node-sass
$ npm install node-sass

竟然也成功了!!!

总结

看过很多大佬在github上开源代码,都建议使用npm install安装依赖包,不建议使用cnpm,说是会遇到未知问题。所以,如果你也遇到该问题,建议使用最后一种方法解决(npm config set sass-binary-site http://npm.taobao.org/mirrors/node-sass)。

GitHub 加速计划 / no / node-sass
8.5 K
1.33 K
下载
:rainbow: Node.js bindings to libsass
最近提交(Master分支:2 个月前 )
6081731a Bumps [actions/setup-node](https://github.com/actions/setup-node) from 3 to 4. - [Release notes](https://github.com/actions/setup-node/releases) - [Commits](https://github.com/actions/setup-node/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/setup-node dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> 9 个月前
62c0f46c Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> 9 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐