node.js npm install 出现错误:`gyp` 失败,退出代码:1

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49348482/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:44:12  来源:igfitidea点击:

npm install with error: `gyp` failed with exit code: 1

node.jswindowsnpmnpm-install

提问by dawn

I am try to install modules on Windows 10 using npm 5.6.0. When I enter npm install I get:

我尝试使用 npm 5.6.0 在 Windows 10 上安装模块。当我输入 npm install 时,我得到:

gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (C:\Users\xiaooming\Desktop\app\node_modules\node-gyp\lib\configure.js:336:16)
gyp ERR! stack at emitTwo (events.js:126:13)
gyp ERR! stack at ChildProcess.emit (events.js:214:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Windows_NT 10.0.16299
gyp ERR! command "D:\Program Files\nodejs\node.exe" "C:\Users\xiaooming\Desktop\app\node_modules\node-gyp\bin\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd C:\Users\xiaooming\Desktop\app\node_modules\node-sass
gyp ERR! node -v v8.10.0
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
Build failed with error code: 1
npm WARN [email protected] No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\xiaooming\AppData\Roaming\npm-cache\_logs18-03-18T13_02_03_946Z-debug.log

it seems like node-sass install error. the environment is bellow:

看起来像 node-sass 安装错误。环境如下:

python version:2.7.14

蟒蛇版本:2.7.14

npm version: 5.6.0

npm 版本:5.6.0

node version:8.10.0

节点版本:8.10.0

ruby version:2.3.3p222 (2016-11-21 revision 56859) [i386-mingw32]

ruby 版本:2.3.3p222 (2016-11-21 修订版 56859) [i386-mingw32]

system:win10(x64)

系统:win10(x64)

node-gyp:3.6.2

节点gyp:3.6.2

and I have installed Microsoft Visual Studio express 2015, the bellow command has executed:

并且我已经安装了 Microsoft Visual Studio express 2015,下面的命令已经执行:

npm config set msvs_version 2015
node-gyp configure --msvs_version=2015
npm install --global --production windows-build-tools

the package.json is:

package.json 是:

{
  "name": "kingt4.0app",
  "version": "1.0.0",
  "description": "an kingt4.0 project.",
  "main": "index.js",
  "scripts": {
    "test": "test.js"
  },
  "keywords": [
    "finance"
  ],
  "author": "kingdom",
  "license": "ISC",
  "devDependencies": {
    "browser-sync": "^2.11.1",
    "gulp": "^3.9.1",
    "gulp-autoprefixer": "^3.1.0",
    "gulp-cache": "^0.4.2",
    "gulp-changed": "^1.3.2",
    "gulp-clean-css": "^2.0.2",
    "gulp-file-include": "^0.13.7",
    "gulp-if": "^2.0.0",
    "gulp-imagemin": "^2.4.0",
    "gulp-rename": "^1.2.2",
    "gulp-sass": "^2.2.0",
    "gulp-sourcemaps": "^1.6.0",
    "gulp.spritesmith": "^6.2.1",
    "imagemin-jpegtran": "^4.3.2",
    "imagemin-pngquant": "^4.2.2",
    "merge-stream": "^1.0.0",
    "normalize.css": "^4.0.0",
    "spritesheet-templates": "^10.1.2",
    "vinyl-buffer": "^1.0.0"
  },
  "dependencies": {
    "remodal": "^1.0.7",
    "slick-carousel": "^1.6.0"
  }
}

how to resolve this problem? thanks for help.

如何解决这个问题?感谢帮助。

回答by user728650

If this is a mac machine (OSX) here is what you can do

如果这是一台 mac 机器 (OSX),你可以这样做

use terminal

使用终端

xcode-select --print-path

then remove installed version

然后删除已安装的版本

sudo rm -r -f /Library/Developer/CommandLineTools

and reinstall

并重新安装

xcode-select --install

that should fix the problem

这应该可以解决问题

Ref: gyp: No Xcode or CLT version detected macOS Catalina

参考:gyp:未检测到 Xcode 或 CLT 版本 macOS Catalina

回答by Soheil

Delete your $HOME/.node-gypdirectory and try again:

删除您的$HOME/.node-gyp目录并重试:

rm -R ~/.node-gyp

回答by Azlan Jamal

this works for me. run command below one by one

这对我有用。下面一一运行命令

rm -rf node_modules
rm package-lock.json
npm update
npm install

回答by Daeron Malnwe

I've faced the same issue on my OSX 10.15with brewas repository; for me was enough doing:

我面临着同样的问题,我OSX 10.15brew的资料库; 对我来说就足够了:

brew unlink python@2
brew link python

回答by Ehsan Ahmadi

Try this command below and see if that wiped away this issue. I have catalina on my mac and this command wiped away that problem.

试试下面的这个命令,看看是否消除了这个问题。我的 mac 上有 catalina,这个命令解决了这个问题。


npm i -g node-gyp@latest && npm config set node_gyp "/usr/local/lib/node_modules/node-gyp/bin/node-gyp.js"

回答by mohammad javad ahmadi

I think delete this directory is better:

我认为删除这个目录更好:

rm -rf ~/.node-gyp/
rm -r node_modules/.bin/;
rm -r build/
npm install <your module>

回答by Aditya Kresna Permana

As described here: https://github.com/nodejs/node-gyp/issues/1634

如此处所述:https: //github.com/nodejs/node-gyp/issues/1634

You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
gyp: Call to '/usr/bin/pg_config --libdir' returned exit status 1 while in binding.gyp. while trying to load binding.gyp

In my case the problem solved by installing libpq-devon my Ubuntu

在我的情况下,通过libpq-dev在我的 Ubuntu 上安装解决了问题

$ sudo apt install libpq-dev

then try to removing the node_modulesand do npm installagain.

然后尝试删除node_modulesnpm install再次执行。

NotePlease take a note that this is not a problem with the node modules, the problem is on the my machine, it doesn't meet the criteria of libpq

注意请注意,这不是节点模块的问题,问题出在我的机器上,它不符合以下标准libpq

回答by Dipten

You may need to install Windows build tools. Check it out this ref.

您可能需要安装 Windows 构建工具。看看这个参考