node.js 需要 node-gyp 的 npm install 在 Windows 上失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35293117/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
npm install that requires node-gyp fails on Windows
提问by Marek Lisy
I have a NPM project that uses bufferutilsand utf-8-validate, both requiring node-gyp to install them. When I do npm install, I get following error:
我有一个使用bufferutils和的 NPM 项目utf-8-validate,两者都需要 node-gyp 来安装它们。当我这样做时npm install,我收到以下错误:
> [email protected] install C:\Users\Marek\WEB\moje-skoly\web-app\node_modules\bufferutil
> node-gyp rebuild
C:\Users\Marek\WEB\moje-skoly\web-app\node_modules\bufferutil {git}{hg}
{lamb} if not defined npm_config_node_gyp (node "C:\Users\Marek\AppData\Roaming\npm\node_modules\npm\bin\node-g
yp-bin\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "" rebuild )
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
bufferutil.cc
C:\Users\Marek\.node-gyp.1.1\include\node\v8.h(18): fatal error C1083: Cannot open include file: 'stddef.h':
No such file or directory [C:\Users\Marek\WEB\moje-skoly\web-app\node_modules\bufferutil\build\bufferutil.vcx
proj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild.0\bin\msbuild.exe` failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (C:\Users\Marek\AppData\Roaming\npm\node_modules\npm\node_modules\nod
e-gyp\lib\build.js:276:23)
gyp ERR! stack at emitTwo (events.js:87:13)
gyp ERR! stack at ChildProcess.emit (events.js:172:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Windows_NT 10.0.10586
gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Users\Marek\AppData\Roaming\npm\node_modules\
npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\Marek\WEB\moje-skoly\web-app\node_modules\bufferutil
gyp ERR! node -v v5.1.1
gyp ERR! node-gyp -v v3.2.1
gyp ERR! not ok
npm WARN install:[email protected] [email protected] install: `node-gyp rebuild`
npm WARN install:[email protected] Exit status 1
Previously it failed because of Python 2.7 not installed, now it is this. It's causing me headaches. What should I do about this?
之前是因为没有安装Python 2.7而失败,现在是这个。这让我很头疼。我该怎么办?
回答by Manuel Beaudru
The answer below stands for a manual installation, but there is a much simpler way : the automatic install.
下面的答案代表手动安装,但有一种更简单的方法:自动安装。
Open Powershell as admin and run npm install -g windows-build-tools.
以管理员身份打开 Powershell 并运行npm install -g windows-build-tools.
The install takes time but it worked like a charm for me !
安装需要时间,但它对我来说就像一个魅力!
回答by Marek Lisy
I found this brilliant solutionon GitHub:
我在 GitHub 上找到了这个绝妙的解决方案:
- Your OS MUST be Windows
- Check that python is in your path by writting
python --versionin the console. If not then - Download python 2.7 (I recommend chocolatey(
choco install python2 -y)) and addpython.exeto your PATH variable. - Aren't you on Windows 7? Skip 5 and 6.
- Check that you have .NET 4.5.1+ installed. If not then
- Download and install .NET 4.5.1(.NET 4.5.2 will also work just fine)
- Download Microsoft Visual C++ Build Tools 2015 Technical Preview
- Use custom install. Install the Windows 8.1 SDK if you haven't already. Apparently, it doesn't matter what OS you're on. You just need the Windows 8.1 SDK.
- Set the npm config variable msvs_version to 2015:
npm config -g set msvs_version 2015 - Do
npm iin what-ever project with node-gyp as a dependency without seeing weird error messages
- 您的操作系统必须是 Windows
- 通过
python --version在控制台中写入来检查 python 是否在您的路径中。如果没有那么 - 下载 python 2.7(我推荐Chocolatey(
choco install python2 -y))并添加python.exe到您的 PATH 变量中。 - 你不是在 Windows 7 上吗?跳过 5 和 6。
- 检查您是否安装了 .NET 4.5.1+。如果没有那么
- 下载并安装 .NET 4.5.1(.NET 4.5.2 也可以正常工作)
- 下载Microsoft Visual C++ 构建工具 2015 技术预览版
- 使用自定义安装。如果尚未安装 Windows 8.1 SDK,请安装。显然,您使用的操作系统无关紧要。您只需要 Windows 8.1 SDK。
- 将 npm 配置变量 msvs_version 设置为 2015:
npm config -g set msvs_version 2015 - 做
npm i什么,曾经与节点GYP作为依赖项目没有看到奇怪的错误信息
My nightmares are gone!
我的噩梦消失了!
回答by J Slick
After wasting many hours over several days trying to install ZeroMQ on Winturds 7 and 10 (including the ridiculous and completely useless installation of .NET and Visual Studio), it was actually easier to create an Ubuntu USB boot disc and install node and ZeroMQ. Now I can actually do productive work.
在花了几天时间尝试在 Winturds 7 和 10 上安装 ZeroMQ 之后(包括荒谬且完全无用的 .NET 和 Visual Studio 安装),实际上创建 Ubuntu USB 启动盘并安装 node 和 ZeroMQ 更容易。现在我实际上可以做富有成效的工作。
回答by Akeel
I couldn't find my solution anywhere else, so thought I'd share.
我在其他任何地方都找不到我的解决方案,所以我想分享一下。
Running node v10.16.3 on Windows 10
在 Windows 10 上运行 node v10.16.3
Install windows-build-tools -
安装 windows-build-tools -
npm install --global --production windows-build-tools
Set the python path explicitly in C:\Users[your username].npmrc - In my case, this is like so:
在 C:\Users[your username].npmrc 中显式设置 python 路径 - 就我而言,这是这样的:
python=c:\users\akeel\.windows-build-tools\python27\python
回答by Andre Morata
Found a solution here: https://spin.atomicobject.com/2019/03/27/node-gyp-windows/
在这里找到了解决方案:https: //spin.atomicobject.com/2019/03/27/node-gyp-windows/
I had to install Windows Build Tools 2015 and then set Node to use it.
我必须安装 Windows Build Tools 2015,然后设置 Node 才能使用它。
Here are the commands I've used:
以下是我使用过的命令:
npm install --global --production windows-build-tools --vs2015
npm config set msvs_version 2015 –global
回答by BogutBeastMode
I was having this issue when updating from an older version of node to node v12. There was a particular issue with bcrypt library. I just uninstalled v12 and installed v10 and everything worked.
从旧版本的节点更新到节点 v12 时,我遇到了这个问题。bcrypt 库存在一个特殊问题。我刚刚卸载了 v12 并安装了 v10,一切正常。
回答by Root Android
Using WSL works for me (windows 10 users only)
使用 WSL 对我有用(仅限 Windows 10 用户)
those who dont know what WSL is simply Linux command shell in windows
那些不知道 WSL 只是 Windows 中的 Linux 命令外壳的人
just follow this guide to install WSL https://wiki.ubuntu.com/WSLand install nodejs and npm my using commands
只需按照本指南安装 WSL https://wiki.ubuntu.com/WSL并安装 nodejs 和 npm my using 命令
sudo apt-get install nodejs npm -y
sudo apt-get install nodejs npm -y

