npm安装错误:`gyp`失败,退出代码:1

时间:2018-03-18 13:36:18

标签: node.js windows npm npm-install

我尝试使用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 kingt4.0app@1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@3.13.1 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@3.13.1 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\_logs\2018-03-18T13_02_03_946Z-debug.log

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

python版本:2.7.14

npm版本:5.6.0

节点版本:8.10.0

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

系统:win10(64)

节点-GYP:3.6.2

我安装了Microsoft Visual Studio express 2015, bellow命令已执行:

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

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"
  }
}

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

12 个答案:

答案 0 :(得分:33)

如果这是Mac计算机(OSX),则可以这样做

使用终端

https://a.com/  Login: f    Pass: fi
https://a.com/  Login: da   Pass: ge
https://a.com/  Login: ts   Pass: mom
https://b.com/  Login: xt   Pass: nnm
https://c.com   Login: 763  Pass: er64
https://c.com   Login: zs   Pass: Te4

然后删除已安装的版本

void main() {
  String var1='name';
  String var2='age';
  Info info= Info(name:"Suman", age:4);
  final json=info.toJson();
  print("NAME = ${json[var1]}");
  print("AGE = ${json[var2]}");
}

class Info {
  String name;
  int age;

  Info({this.name, this.age});

  Info.fromJson(Map<String, dynamic> json) {
    name = json['name'];
    age = json['age'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['name'] = this.name;
    data['age'] = this.age;
    return data;
  }
}

然后重新安装

xcode-select --print-path

应该解决的问题

参考:gyp: No Xcode or CLT version detected macOS Catalina

答案 1 :(得分:10)

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

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

答案 2 :(得分:3)

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

rm -R ~/.node-gyp

答案 3 :(得分:3)

请在下面尝试此命令,看看是否可以消除此问题。我的Mac上装有Catalina,此命令消除了该问题。


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

答案 4 :(得分:2)

我在安装使用 webpack 的项目时遇到了同样的问题。 我确实按照有关 xcode-select 重新安装的步骤进行了操作,但它给了我同样的错误。为此,我做了一个简单的修复,我单独安装了 node-sass,因为它是一个出错的地方。

npm i node-sass

然后再次运行安装,

npm i

它对我有用✌️

有时节点包有旧版本,项目也需要升级。为此,您在安装时会收到与漏洞相关的警告。为此运行以下命令(在终端输出中也提到),

npm audit fix

答案 5 :(得分:1)

我遇到了类似的问题,我的 MSVS_version 是 2019。我尝试了以下步骤并解决了问题。

npm install --global --production windows-build-tools

然后

npm config set msvs_version 2017
npm i

答案 6 :(得分:0)

我认为删除此目录更好:

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

答案 7 :(得分:0)

如此处所述: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

就我而言,问题是通过在Ubuntu上安装libpq-dev来解决的

$ sudo apt install libpq-dev

然后尝试删除node_modules,然后再次执行npm install

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

的条件

答案 8 :(得分:0)

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

答案 9 :(得分:0)

我在OSX 10.15作为存储库的brew上遇到了同样的问题;对我来说足够了:

brew unlink python@2
brew link python

答案 10 :(得分:0)

仅适用于MAC

步骤:1

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

步骤:2

sudo xcode-select --switch /Library/Developer/CommandLineTools/

答案 11 :(得分:0)

如果您删除package-lock.json然后运行

npm update
npm install