Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
316 views
in Technique[技术] by (71.8m points)

javascript - NPM install fails with node-gyp

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'

It appears to be coming from the node-gyp module :

c:Program Files odejs ode_modules pm ode_modules ode-gypsrcwin_delay_lo ad_hook.c(13):

fatal error C1083: Cannot open include file: 'windows.h': No suc h file or directory [D: gs-frontend-next ode_modulesrowser-sync ode_module ssocket.io ode_modulesengine.io ode_modulesws ode_modulesufferutiluil dinding.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.

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

The full error looks like this :

c:Program Files odejs ode_modules pm ode_modules ode-gypsrcwin_delay_lo ad_hook.c(13):

fatal error C1083: Cannot open include file: 'windows.h': No suc h file or directory [D: gs-frontend-next ode_modulesrowser-sync ode_module ssocket.io ode_modulesengine.io ode_modulesws ode_modulesufferutiluil dinding.sln]

gyp ERR! build error gyp ERR! stack Error: C:WindowsMicrosoft.NETFrameworkv4.0.30319msbuild.exe failed with exit code: 1 stack at ChildProcess.onExit (C:Program Files odejs ode_modules pm ode _modules ode-gyplibuild.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 odejs ode.exe" "C:Program Files odej s ode_modules pm ode_modules ode-gypin ode-gyp.js" "rebuild" gyp ERR! cwd D: gs-frontend-next ode_modulesrowser-sync ode_modulessocket. io ode_modulesengine.io ode_modulesws ode_modulesufferutil 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: gs-frontend-next ode_modulesgulp-imagemin od e_modulesimagemin ode_modulesimagemin-gifsicle ode_modulesgifsicle node lib/install.js

Out pacakge.json looks like this :

{
  "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"
  }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

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.

The following quote is from the Windows installation section:

  • 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.x is 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.

Common instructions for Python configuration:

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

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.

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

.NET Framework 4.5.1

Python 2.7

Microsoft's Node.js Guidelines for Windows


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...