Javascript NPM 安装因 node-gyp 失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33896511/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 15:36:30  来源:igfitidea点击:

NPM install fails with node-gyp

javascriptnode.jsnpmnode-gyp

提问by Oliver Watkins

We are having problems running "npm install"on our project. A certain file cannot be found :

我们在项目上运行“npm install”时遇到问题。找不到某个文件:

fatal error C1083: Cannot open include file: 'windows.h'

It appears to be coming from the node-gypmodule :

它似乎来自node-gyp模块:

c:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\src\win_delay_lo ad_hook.c(13):

fatal error C1083: Cannot open include file: 'windows.h': No suc h file or directory [D:\ngs-frontend-next\node_modules\browser-sync\node_module s\socket.io\node_modules\engine.io\node_modules\ws\node_modules\bufferutil\buil d\binding.sln]

c:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\src\win_delay_lo ad_hook.c(13):

致命错误 C1083:无法打开包含文件:'windows.h':没有 suc h 文件或目录 [D:\ngs-frontend-next\node_modules\browser-sync\node_module s\socket.io\node_modules\engine.io\ node_modules\ws\node_modules\bufferutil\buil d\binding.sln]

This node-gyp seems to be a never ending source of pain for us. At first it complained that it needed python, so we installed that. Then it complained that it needed VCBuild, which we installed (using .NET 2.0 SDK), now we have this error. It's almost as if the errors are getting more and more obscure, and it feels like we are going down some wrong path.

这个 node-gyp 对我们来说似乎是一个永无止境的痛苦之源。起初它抱怨它需要python,所以我们安装了它。然后它抱怨它需要我们安装的 VCBuild(使用 .NET 2.0 SDK),现在我们有这个错误。几乎就好像错误变得越来越模糊,感觉就像我们走上了一条错误的道路。

The strange thing is, that other people in our team have zero problems running the npm-install.

奇怪的是,我们团队中的其他人在运行 npm-install 时遇到了零问题。

The full error looks like this :

完整的错误如下所示:

c:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\src\win_delay_lo ad_hook.c(13):

fatal error C1083: Cannot open include file: 'windows.h': No suc h file or directory [D:\ngs-frontend-next\node_modules\browser-sync\node_module s\socket.io\node_modules\engine.io\node_modules\ws\node_modules\bufferutil\buil d\binding.sln]

gyp ERR! build error gyp ERR! stack Error: C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exefailed with exit code: 1 stack at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node _modules\node-gyp\lib\build.js:270: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_proces s.js:200:12) gyp ERR! System Windows_NT 6.1.7601 gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodej s\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild" gyp ERR! cwd D:\ngs-frontend-next\node_modules\browser-sync\node_modules\socket. io\node_modules\engine.io\node_modules\ws\node_modules\bufferutil gyp ERR! node -v v4.2.2 gyp ERR! node-gyp -v v3.0.3 gyp ERR! not ok npm WARN optional dep failed, continuing [email protected]

[email protected] postinstall D:\ngs-frontend-next\node_modules\gulp-imagemin\nod e_modules\imagemin\node_modules\imagemin-gifsicle\node_modules\gifsicle node lib/install.js

c:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\src\win_delay_lo ad_hook.c(13):

致命错误 C1083:无法打开包含文件:'windows.h':没有 suc h 文件或目录 [D:\ngs-frontend-next\node_modules\browser-sync\node_module s\socket.io\node_modules\engine.io\ node_modules\ws\node_modules\bufferutil\buil d\binding.sln]

吉普错误!构建错误 gyp ERR!堆栈错误: C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe退出代码失败:1 堆栈在 ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node _modules\node-gyp\lib\build.js:270:23) gyp ERR!堆栈在emitTwo (events.js:87:13) gyp ERR!堆栈在 ChildProcess.emit (events.js:172:7) gyp ERR!堆栈在 Process.ChildProcess._handle.onexit (internal/child_proces s.js:200:12) gyp ERR!系统 Windows_NT 6.1.7601 gyp ERR!命令 "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodej s\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "重建" gyp ERR!cwd D:\ngs-frontend-next\node_modules\browser-sync\node_modules\socket.cwd io\node_modules\engine.io\node_modules\ws\node_modules\bufferutil gyp ERR!节点 -v v4.2.2 gyp 错误!node-gyp -v v3.0.3 gyp 错误!不行 npm WARN 可选的 dep 失败,继续 [email protected]

[email protected] postinstall D:\ngs-frontend-next\node_modules\gulp-imagemin\node e_modules\imagemin\node_modules\imagemin-gifsicle\node_modules\gifsicle node lib/install.js

Out pacakge.jsonlooks like this :

pacakge.json看起来像这样:

{
  "name": "Fast-nunjucks",
  "version": "0.0.1",
  "description": "A simple boilerplate using nunjucks as a template engine",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/willianjusten/Fast-nunjucks.git"
  },
  "keywords": [
    "nunjucks",
    "node",
    "gulp",
    "stylus"
  ],
  "author": "Willian Justen de Vasconcellos",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/willianjusten/Fast-nunjucks/issues"
  },
  "homepage": "https://github.com/willianjusten/Fast-nunjucks",
  "devDependencies": {
    "autoprefixer-stylus": "^0.7.1",
    "browser-sync": "^2.8.2",
    "gulp": "^3.9.0",
    "gulp-cache": "^0.3.0",
    "gulp-concat": "^2.6.0",
    "gulp-if": "^1.2.5",
    "gulp-imagemin": "^2.3.0",
    "gulp-minify-html": "^1.0.4",
    "gulp-nunjucks-html": "^1.2.2",
    "gulp-order": "^1.1.1",
    "gulp-plumber": "^1.0.1",
    "gulp-stylus": "^2.0.6",
    "gulp-uglify": "^1.2.0",
    "gulp-util": "^3.0.6",
    "jeet": "^6.1.2",
    "kouto-swiss": "^0.11.13",
    "minimist": "^1.1.3",
    "rupture": "^0.6.1"
  },
  "dependencies": {
    "gulp-install": "^0.6.0"
  }
}

回答by Sourav Paul

The error messages have caused confusion for me and have not helped me in resolving the errors completely.

错误消息让我感到困惑,并没有帮助我完全解决错误。

The README.mdfor node-gypproject does a better job of listing down the installation instructions for Unix, Max OS X and Windows.

README.md节点GYP项目做下来的Unix,最大OS X和安装说明书列出的工作做得更好的Windows

In Windowssystems you can either go with Option 1 or Option 2 but the main thing is that you need to install the Visual C++ Build Tools.

Windows系统中,您可以选择 Option 1 或 Option 2,但主要的是您需要安装Visual C++ Build Tools

The following quote is from the Windowsinstallation section:

以下引用来自Windows安装部分:

  • On Windows:
    • Visual C++ Build Environment:
      • Option 1: Install Visual C++ Build Tools using the Default Install option.
      • Option 2: Install Visual Studio 2015 (or modify an existing installation) and select Common Tools for Visual C++during setup. This also works with the free Community and Express for Desktop editions.

      [Windows Vista / 7 only] requires .NET Framework 4.5.1
    • Install Python 2.7 (v3.x.xis not supported), and run
      npm config set python python2.7
      (or see below for further instructions on specifying the proper Python version and path.)
    • Launch cmd,
      npm config set msvs_version 2015

If the above steps didn't work for you, please visit Microsoft's Node.js Guidelines for Windows for additional tips.

  • 在 Windows 上:
    • Visual C++ 构建环境:
      • 选项 1:使用默认安装选项安装 Visual C++ 构建工具。
      • 选项 2:安装 Visual Studio 2015(或修改现有安装)并在安装过程中选择Visual C++ 的通用工具。这也适用于免费的 Community 和 Express for Desktop 版本。

      [仅适用于 Windows Vista / 7] 需要 .NET Framework 4.5.1
    • 安装 Python 2.7(不支持v3.xx),然后运行
      npm config set python python2.7
      (或参阅下文以获取有关指定正确 Python 版本和路径的进一步说明。)
    • 启动cmd,
      npm config set msvs_version 2015

如果上述步骤对您不起作用,请访问 Microsoft 的 Windows Node.js 指南以获取其他提示。

Common instructions for Python configuration:

Python配置的常用说明:

If you have multiple Python versions installed, you can identify which Python version node-gyp uses by setting the '--python' variable:

如果您安装了多个 Python 版本,您可以通过设置 '--python' 变量来确定 node-gyp 使用的 Python 版本:

$ node-gyp --python /path/to/python2.7

If node-gyp is called by way of npm and you have multiple versions of Python installed, then you can set npm's 'python' config key to the appropriate value:

如果通过 npm 调用 node-gyp 并且您安装了多个版本的 Python,那么您可以将 npm 的“python”配置键设置为适当的值:

$ npm config set python /path/to/executable/python2.7

Successfully configured my system following the above instructions.

按照上述说明成功配置了我的系统。

System Info

系统信息

λ ver

Microsoft Windows [Version 6.1.7601]

λ node -v
v6.2.0
λ npm -v
3.9.2

Links to relevant tools / articles:

相关工具/文章的链接:

Visual C++ Build Tools

Visual C++ 构建工具

Visual Studio 2015

视觉工作室 2015

.NET Framework 4.5.1

.NET 框架 4.5.1

Python 2.7

蟒蛇 2.7

Microsoft's Node.js Guidelines for Windows

适用于 Windows 的 Microsoft 的 Node.js 指南

回答by David Vega

Try to install again with --force option:

尝试再次安装--force option

npm install --force

If this doesn't work try to update npm globally:

如果这不起作用,请尝试全局更新 npm:

npm update -g npm 

and try again with the --forceoption.

并使用该--force选项重试。

回答by Softinio

The last time I saw a similar error it was because I was using the wrong version of npmand/or nodefor one of my dependencies. Try upgrading these and try again.

我最后一次看到类似的错误是因为我使用了错误的版本npm和/或node我的一个依赖项。尝试升级这些并重试。

Before trying again remove your node_modulesdirectory.

在再次尝试删除您的node_modules目录之前。

You may need to investigate what versions of npmand nodeyour dependencies need. You could try the latest versions of all your dependencies, node and npm.

您可能需要调查需要哪些版本npmnode您的依赖项。您可以尝试所有依赖项、node 和 npm 的最新版本。

Check what versions your colleagues are using.

检查您的同事使用的版本。

What OS are you using? That can have an impact as version of CLANG maybe different.

你使用的是什么操作系统?这可能会产生影响,因为 CLANG 的版本可能不同。

回答by sabari

  1. Install VC++ Build Tools Technical Preview [Windows 7 only] requires .NET Framework 4.5.1

  2. Install Python 2.7, and add it to your PATH, npm config set python python2.7

  3. Launch cmd, npm config set msvs_version 2015 --global (this is instead of npm install [package name] --msvs_version=2015 every time.)

  1. 安装 VC++ Build Tools Technical Preview [仅限 Windows 7] 需要 .NET Framework 4.5.1

  2. 安装 Python 2.7,并将其添加到您的 PATH,npm config set python python2.7

  3. 启动 cmd,npm config set msvs_version 2015 --global(这不是每次 npm install [package name] --msvs_version=2015。)

4.SO MUCH npm install :tada:

4.这么多 npm install :tada:

回答by Java Xu

Post my solution here in case anyone like me using Windows 10still has the error after installing many Microsoft associated build tools.

在这里发布我的解决方案,以防像我这样使用Windows 10的人在安装了许多与 Microsoft 相关的构建工具后仍然出现错误。

All you need are:

您只需要:

Windows 10 64 bit

python 2.7.x

Visual Studio 2013

视窗 10 64 位

蟒蛇 2.7.x

视觉工作室 2013

I've tried Visual Studio 2015 before but it didn't work at all.

我之前尝试过 Visual Studio 2015,但它根本不起作用。



  1. First of all, I uninstall all the Microsoft associated build tools. (If you didn't install anything to try to solve this problem before, skip this step.)

  2. Install Visual Studio 2013.

  3. Config npm as @Sourav said:

  1. 首先,我卸载了所有与 Microsoft 相关的构建工具。(如果您之前没有安装任何东西来尝试解决此问题,请跳过此步骤。)

  2. 安装 Visual Studio 2013。

  3. 像@Sourav 所说的那样配置 npm:

Config python:

npm config set python /path/to/python2.7

Config msvs_version:

npm config set msvs_version 2013

配置蟒蛇:

npm config set python /path/to/python2.7

配置 msvs_version:

npm config set msvs_version 2013

Run a npm installor the npm command which occurs this error. It works for me!

运行npm install发生此错误的a或 npm 命令。这个对我有用!

BTW, this solution is from here.

顺便说一句,这个解决方案来自这里

回答by Orr

for this solved it ( OS X ):

为此解决了它(OS X):

    rm -rf  ~/.node_gyp and
    sudo npm install -g [email protected]
    cd /usr/local/lib sudo ln -s ../../lib/libSystem.B.dylib libgcc_s.10.5.dylib 
    brew install gcc
    npm install

回答by WitVault

For Windows 8 or 10:

对于 Windows 8 或 10:

Assuming node and npm installed already.

假设已经安装了 node 和 npm。

My node and npm version (At the time of writing this answer) :

我的节点和 npm 版本(在撰写此答案时):

node : 8.9.4

节点:8.9.4

npm : 5.6.0

npm : 5.6.0

  1. First install python 2.x

  2. Make sure it is available on path

  3. Install Visual Studio Installer

  4. After installation, run it

  5. A new interface will open it where you can select various options.
  6. Now select Build Tools for Visual Studio 2017from the available options and install it. You don't need to install Visual Studio.
  1. 首先安装python 2.x

  2. 确保它在路径上可用

  3. 安装 Visual Studio 安装程序

  4. 安装后,运行

  5. 将打开一个新界面,您可以在其中选择各种选项。
  6. 现在从可用选项中选择Build Tools for Visual Studio 2017并安装它。你不需要安装 Visual Studio。

enter image description hereAfter the installation it should work perfectly.

在此处输入图片说明安装后它应该可以正常工作。

回答by EvilBurrito

Hey please try to install the windows build tools(global npm package)

嘿,请尝试安装windows 构建工具(全局 npm 包)

This will fix your problem :-) You should be able to use your npm install command afterwards.

这将解决您的问题:-) 之后您应该可以使用您的 npm install 命令。

回答by Javier Aviles

Based on the node-gyp README, update npm npm i npm -g, and will bring in a newer version of node-gyp.

基于node-gyp README,更新 npm npm i npm -g,并将引入更新版本的 node-gyp。

Hint: if you are on windowsperform npm install --global --production windows-build-toolsfrom an elevated PowerShell or CMD.exe (run as Administrator).

提示:如果你对窗口进行npm install --global --production windows-build-tools从提升的PowerShell或cmd.exe,(以管理员身份运行)。