使用node-gyp进行NPM安装失败 [英] NPM install fails with node-gyp

查看:141
本文介绍了使用node-gyp进行NPM安装失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在项目中运行npm install时遇到问题。无法找到某个文件:

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

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

它似乎来自 node-gyp 模块:


c:\Program
Files\\\
odejs\\\
ode_modules\\\
pm\\\
ode_modules\\\
ode-gyp\src\win_delay_lo
ad_hook.c(13):

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

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

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

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.

奇怪的是,我们其他人团队在运行npm-install时没有问题。

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

完整错误如下所示:


c:\Program
Files \\\
odejs\\\
ode_modules\\\
pm\\\
ode_modules\\\
ode-gyp\src\win_delay_lo
ad_hook.c(13):

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

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

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!构建错误gyp ERR!堆栈错误:
C:\ Windows \ Microsoftoft.NET\Framework\v4.0.30319\msbuild.exe 退出
退出代码:ChildProcess.onExit上的1个堆栈(C:\Program
Files \\\
odejs \\\
ode_modules \\\
pm \ node
_modules\\\
ode-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 \\\
odejs\\\
ode.exeC:\Program Files \\\
odej
s \\\
ode_modules \\\
pm \ node_modules \ node-gyp \\ \\ bin\\\
ode-gyp.js
rebuildgyp ERR! cwd
D:\ ngs-frontend-next \\\
ode_modules\browser-sync \ node_modules \ socket。
io\\\
ode_modules\engine.io\\\
ode_modules\ws\\\
ode_modules\bufferutil gyp
ERR! node -v v4.2.2 gyp ERR! node-gyp -v v3.0.3 gyp ERR!不行npm
WARN可选dep失败,继续utf-8-validate@1.2.1

gyp ERR! build error gyp ERR! stack Error: C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe failed 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 utf-8-validate@1.2.1


gifsicle@3.0.3 postinstall D:\\\
gs-frontend-next \\\
ode_modules \gulp-imagemin \\\
od
e_modules\ imagemin\\\
ode_modules\magemin-gifsicle\\\
ode_modules\gifsicle
node lib / install .js

gifsicle@3.0.3 postinstall D:\ngs-frontend-next\node_modules\gulp-imagemin\nod e_modules\imagemin\node_modules\imagemin-gifsicle\node_modules\gifsicle node lib/install.js


Out 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"
  }
}


推荐答案

错误消息给我造成了混乱,并没有帮助我完全解决错误。

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

README.md 了解 node-gyp 项目更好地列出了Unix的安装说明,Max OS X和 Windows

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

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

In Windows systems 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 安装部分:

The following quote is from the Windows installation section:


  • 在Windows上:

    • Visual C ++ Build Envi ronment:

      • 选项1:使用默认安装选项安装Visual C ++ Build Tools。

      • 选项2:安装Visual Studio 2015(或修改现有安装)并在安装过程中选择 Visual C ++的通用工具。这也适用于免费的社区和Express for Desktop版本。

      • 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.
      npm config set python python2.7

      (或参见下面有关指定正确的Python版本和路径的进一步说明。)


    • 启动cmd,

      (or see below for further instructions on specifying the proper Python version and path.)

    • Launch cmd,

      npm config set msvs_version 2015


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

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

      Python配置的常用说明:

      Common instructions for Python configuration:


      如果安装了多个Python版本,可以通过设置'--python'变量来识别哪个Python版本的node-gyp:

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



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




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

      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 config set python /path/to/executable/python2.7

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

      Successfully configured my system following the above instructions.

      系统信息

      λ 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 Studio 2015

      .NET Framework 4.5.1

      Python 2.7

      Microsoft的Node.js Windows指南

      这篇关于使用node-gyp进行NPM安装失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆