首页 文章

使用node-gyp进行NPM安装失败

提问于
浏览
11

我们在项目上运行 "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 回答

  • 0

    错误消息给我带来了困惑,并没有帮助我完全解决错误 .

    node-gyp for node-gyp项目可以更好地列出Unix,Max OS X和 Windows 的安装说明 .

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

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

    在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的Node.js Windows指南以获取更多提示 .

    Python配置的常用说明:

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

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

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

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

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

    System Info

    λ ver
    
    Microsoft Windows [Version 6.1.7601]
    
    λ node -v
    v6.2.0
    λ npm -v
    3.9.2
    

    相关工具/文章的链接:

    Visual C++ Build Tools

    Visual Studio 2015

    .NET Framework 4.5.1

    Python 2.7

    Microsoft's Node.js Guidelines for Windows

  • 0

    尝试使用 --force option 再次安装:

    npm install --force
    

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

    npm update -g npm
    

    然后使用 --force 选项再试一次 .

  • 1

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

    在再次尝试之前删除 node_modules 目录 .

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

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

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

  • 3
    • 安装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:

  • 3

    在这里发布我的解决方案,以防任何像我这样的人使用 Windows 10 在安装许多Microsoft关联的构建工具后仍然有错误 .

    你所需要的只是:

    Windows 10 64位python 2.7.x Visual Studio 2013

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


    • 首先,我卸载所有与Microsoft相关的构建工具 . (如果您之前没有安装任何试图解决此问题的任何内容,请跳过此步骤 . )

    • 安装Visual Studio 2013 .

    • 配置npm为@Sourav说:

    Config python:npm config set python /path/to/python2.7
    配置msvs_version:npm config设置msvs_version 2013

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

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

  • 10

    为此解决了它(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
    
  • 4

    对于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 .

    enter image description here
    安装后应该可以正常工作 .

相关问题