NPM安装在node-gyp中失败
我们在我们的项目上运行“npm install”时遇到问题。 某个文件无法find:
fatal error C1083: Cannot open include file: 'windows.h'
它似乎来自node-gyp模块:
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 \ node_modules \ browser-sync \ node_module s \ socket.io \ node_modules \ engine.io \ node_modules \ ws \ node_modules \ bufferutil \ buil d \ binding.sln]
这个节点似乎对我们来说是一个永无止境的痛苦来源。 起初它抱怨说,它需要python,所以我们安装了。 然后它抱怨说,它需要VCBuild,我们安装(使用.NET 2.0 SDK),现在我们有这个错误。 就好像这些错误变得越来越模糊,感觉就像我们走错了路。
奇怪的是,我们团队中的其他人在运行npm-install时没有任何问题。
完整的错误看起来像这样:
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 \ 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错误gyp ERR! 堆栈错误:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe
失败,退出代码: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(内部/ 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”“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! 不行npm WARN可选dep失败,继续utf-8-validate@1.2.1gifsicle@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
出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" } }
错误信息给我造成了困惑,并没有帮助我完全解决错误。
node- gyp项目的README.md能够更好地列出Unix,Max OS X和Windows的安装说明。
在Windows系统中,您可以使用选项1或选项2,但主要的是您需要安装Visual C ++构build工具 。
以下报价来自Windows安装部分:
- 在Windows上:
- Visual C ++构build环境:
- 选项1:使用“默认安装”选项安装Visual C ++构build工具。
- 选项2:安装Visual Studio 2015(或修改现有安装),并在安装过程中select用于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版本和path的进一步说明。)
- 启动cmd,
npm config set msvs_version 2015
如果上述步骤不适合您,请访问Microsoft的Node.js Windows准则获取更多提示。
Pythonconfiguration的常用说明:
如果您安装了多个Python版本,则可以通过设置“–python”variables来确定哪个Python版本node-gyp使用:
$ node-gyp --python /path/to/python2.7
如果通过npm调用node-gyp,并且安装了多个Python版本,则可以将npm的“python”configuration项设置为适当的值:
$ npm config set python /path/to/executable/python2.7
按照上述说明成功configuration我的系统。
系统信息
λ ver Microsoft Windows [Version 6.1.7601] λ node -v v6.2.0 λ npm -v 3.9.2
相关工具/文章的链接:
Visual C ++构build工具
Visual Studio 2015
.NET Framework 4.5.1
Python 2.7
微软针对Windows的Node.js指南
上次我看到一个类似的错误,这是因为我的一个依赖关系使用了npm
和/或node
的错误版本。 尝试升级这些,然后重试。
在尝试再次删除您的node_modules
目录之前。
您可能需要调查您的依赖关系需要的npm
和node
版本。 您可以尝试所有依赖项的最新版本,node和npm。
检查您的同事正在使用的版本。
你在使用什么操作系统? 这可能会产生影响,因为CLANG的版本可能不同。
-
安装VC ++构build工具技术预览[仅限Windows 7]需要.NET Framework 4.5.1
-
安装Python 2.7,并将其添加到您的PATH,npmconfiguration设置python python2.7
-
启动cmd,npm config set msvs_version 2015 –global(这不是每次npm install [包名] –msvs_version = 2015)
4.SO很多npm安装:tada:
尝试使用--force option
再次安装:
npm install --force
如果这不起作用,请尝试全局更新npm:
npm update -g npm
并使用--force
选项重试。
为此解决了它(OS X):
rm -rf ~/.node_gyp and sudo npm install -g node-gyp@3.4.0 cd /usr/local/lib sudo ln -s ../../lib/libSystem.B.dylib libgcc_s.10.5.dylib brew install gcc npm install
在这里发布我的解决scheme,以防万一使用Windows 10的用户在安装了许多Microsoft关联的构build工具后仍然出现错误。
所有你需要的是:
Windows 10 64位
python 2.7.x
Visual Studio 2013
我已经尝试过Visual Studio 2015,但它根本不工作。
-
首先,我卸载所有的微软相关的构build工具。 (如果您之前没有安装任何设备来解决此问题,请跳过此步骤。)
-
安装Visual Studio 2013。
-
configurationnpm作为@Sourav说:
configurationpython:
npm config set python /path/to/python2.7
configurationmsvs_version:
npm config set msvs_version 2013
运行npm install
或发生此错误的npm命令。 这个对我有用!
顺便说一下,这个解决scheme是从这里 。