我只是在学习windows上的nodejs . 似乎node-gyp包的设置非常痛苦 . 我在网上尝试了很多指南,但我觉得我在玩一个猜谜游戏 . Windows版本非常新鲜,只有一周左右的时间 .
官方页面(https://github.com/nodejs/node-gyp)说:
(试图采取最简单的路径)
npm install -g node-gyp
npm install --global --production windows-build-tools
If the above didn't work" go to https://github.com/Microsoft/nodejs-guidelines/blob/master/windows-environment.md#compiling-native-addon-modules
如果我只是运行 node-gyp ,我明白了
找不到模块:
'C:\ Program Files \ nodejs \ node_modules \ npm \ node_modules \ node_modules \ node-gyp \ bin \ node-gyp.js'(等) . 即使该文件存在 .
我甚至尝试卸载节点,清除%appdata%缓存等并删除其他内容 .
如果我尝试安装依赖于node-gyp的东西,我得到:
.. \ src \ ursaNative.cc(157):警告C4244 :(等)..
呃!堆栈错误: msbuild
失败,退出代码:1 gyp ERR! ChildProcess.onExit上的堆栈(C:\ Program Files \ nodejs \ node_modules \ npm \ node_modules \ node-gyp \ lib \ build.js:258:23)
我花了很多很多小时 - 我无法相信这是多么痛苦 .
我有
-
安装了VS Tools(如上所述)
-
安装了C编译器
-
已安装构建工具https://www.visualstudio.com/thank-you-downloading-visual-studio/?sku=BuildTools&rel=15
-
尝试将环境设置为VS2015(和VS 2017)
-
试图遵循许多堆栈溢出修复和帖子 . 当然有一条可靠的道路可以实现这一目标 .
-
本地和全局卸载/重新安装的各种组合 .
任何想法从哪里开始?
4 回答
您的node-gyp模块是从NPM初始化的,但很可能它的正确路径没有添加到系统中的环境变量中,只需将其添加到系统变量即可 . 检查路径变量是否有“ C://Users/abc/AppData/Roaming/npm ”,如果没有,请添加它 .
还要检查python是否已添加到环境变量中 .
干杯!
这是在问题1463中提出的 . 这似乎是遵循node-gyp install -g和npm install的文档说明的错误--global --production windows-build-tools
我发现了一个很简单的解决方案
如果node_gyp在你的磁盘上,就像它应该的那样:“C:\ Program Files \ nodejs \ node_modules \ npm \ node_modules \ node-gyp \ bin \ node-gyp.js”
但是错误消息需要这样:“C:\ Program Files \ nodejs \ node_modules \ npm \ node_modules \ node_modules \ node-gyp \ bin \ node-gyp.js”
您只需在“C:\ Program Files \ nodejs \ node_modules \ npm \ node_modules \”下添加一个额外的node_modules文件夹
然后将整个现有的\ node-gyp文件夹复制到新的\ node_modules \ node_modules文件夹中 .
您有一个冗余的node-gyp文件夹,但配置和构建步骤现在将按预期工作 .
至少那对我有用 .
浏览Visual Studio Code安装程序,在MSBuild Tools上,选择“更多”下拉菜单,然后单击“修复”
.
您必须按照README https://github.com/nodejs/node-gyp#option-1中的说明安装
windows-build-tools