我们在项目上运行 "npm install" 时遇到问题 . 无法找到某个文件:
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 \ binding.sln]
这个节点gyp似乎是我们痛苦的永无止境的源头 . 起初它抱怨它需要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 \ ndound.sln] gyp ERR!构建错误gyp ERR!堆栈错误:C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ msbuild.exe失败,退出代码:ChildProcess.onExit上的1个堆栈(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”“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.1 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"
}
}
7 回答
错误消息给我带来了困惑,并没有帮助我完全解决错误 .
node-gyp for node-gyp项目可以更好地列出Unix,Max OS X和 Windows 的安装说明 .
在 Windows 系统中,您可以使用选项1或选项2,但主要的是您需要安装Visual C++ Build Tools .
以下引用来自 Windows 安装部分:
Python配置的常用说明:
按照上述说明成功配置了我的系统 .
System Info
相关工具/文章的链接:
Visual C++ Build Tools
Visual Studio 2015
.NET Framework 4.5.1
Python 2.7
Microsoft's Node.js Guidelines for Windows
尝试使用
--force option
再次安装:如果这不起作用,请尝试全局更新npm:
然后使用
--force
选项再试一次 .我最后一次看到类似的错误是因为我使用了错误版本的
npm
和/或node
作为我的一个依赖项 . 尝试升级这些并重试 .在再次尝试之前删除
node_modules
目录 .您可能需要调查您的依赖项所需的
npm
和node
的版本 . 您可以尝试所有依赖项的最新版本,node和npm .检查您的同事使用的版本 .
你用的是什么操作系统?这可能会产生影响,因为CLANG的版本可能会有所不同 .
安装VC构建工具技术预览[仅限Windows 7]需要.NET Framework4.5.1
安装Python 2.7,并将其添加到PATH,npm config set python python2.7
启动cmd,npm config set msvs_version 2015 --global(这不是每次npm install [包名] --msvs_version = 2015 . )
4.很多npm安装:tada:
在这里发布我的解决方案,以防任何像我这样的人使用 Windows 10 在安装许多Microsoft关联的构建工具后仍然有错误 .
你所需要的只是:
我之前尝试过Visual Studio 2015,但它根本不起作用 .
首先,我卸载所有与Microsoft相关的构建工具 . (如果您之前没有安装任何试图解决此问题的任何内容,请跳过此步骤 . )
安装Visual Studio 2013 .
配置npm为@Sourav说:
运行
npm install
或发生此错误的npm命令 . 这个对我有用!顺便说一句,这个解决方案来自here .
为此解决了它(OS X):
对于Windows 8或10:
假设已经安装了node和npm .
我的节点和npm版本(在写这个答案的时候):
节点:8.9.4
npm:5.6.0
首先安装python 2.x
确保它在路径上可用
安装Visual Studio Installer
安装完成后,运行它
将打开一个新界面,您可以在其中选择各种选项 .
现在从可用选项中选择 Build Tools for Visual Studio 2017 并进行安装 . 您不需要安装Visual Studio .
安装后应该可以正常工作 .