npm install with error: `gyp` failed with exit code: 1
Asked Answered
S

27

76

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

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\_logs\2018-03-18T13_02_03_946Z-debug.log

It seems like node-sass install error. The environment is below:

Python version: 2.7.14

npm version: 5.6.0

node version: 8.10.0

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

system: win10(x64)

node-gyp: 3.6.2

And I have installed Microsoft Visual Studio express 2015, the below command has been executed:

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

How to resolve this problem? thanks for help.

Squelch answered 18/3, 2018 at 13:36 Comment(3)
Possible duplicate of Cannot install node modules that require compilation on Windows 7 x64/VS2012Ungenerous
use node v7.9.x and install vs2015 and windows sdk then it is ok.Squelch
How the hell node got so popular since it's almost impossible to install standard project in a normal way. -_-Lowe
H
98

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

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

Holifield answered 26/3, 2020 at 4:17 Comment(5)
Personally, I need to do it couple times per year. 🤷‍♂️Hards
This command works. But like Mark Twain, I end up repeating it periodically.Datestamp
This worked for me as well. Took about a minute to run these commands, so it was super quick. Thanks!Kendyl
I never had to do this with my previous osx machine. Now I am doing it daily. :(Anility
Well looks like I just wiped my command line tools. On MacOS 13.5 the final command just says error: command line tools are already installed, use "Software Update" in System Settings to install updatesReceivable
L
46

this works for me. run command below one by one

rm -rf node_modules
rm package-lock.json
npm update
npm install
Lila answered 2/3, 2020 at 4:33 Comment(2)
Didn't worked for me.Baliol
removing package-lock.json is asking for more troublesJeremiahjeremias
R
25
$ npm i --ignore-script 

I tried different ways to solve this issue, finally, this comment simply help to install node packages without any errors.

Rumble answered 14/2, 2022 at 5:40 Comment(1)
Yes, that does not show any errors. Still, I would not call it a solution. Some script failed and something is still broken/missing. Question is what failed and why.Nabala
M
17

This error is due to obsolete packages. It can also be due to a version change of NodeJS, npm or other packages and/or package managers. To solve it you must remove node_modules and execute the command:

npm i --ignore-script

It's possible that node-sass gives you an error because it is already obsolete, so install npm sass. In case it's another package, just check the current version and update it.

Marlette answered 28/1, 2022 at 15:23 Comment(0)
C
16

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.


npm i -g node-gyp@latest && npm config set node_gyp "/usr/local/lib/node_modules/node-gyp/bin/node-gyp.js"
Corduroy answered 4/4, 2020 at 18:3 Comment(3)
I ran npm i -g node-pre-gyp@latest and it fixed my issue. This was on a Mac running Big SurQuartziferous
@WhatWouldBeCool this worked for me too, on Ventura 13.1Kailakaile
Looks like node-pre-gyp is no longer supported and is replaced by npm i -g @mapbox/node-pre-gyp@latestQuartziferous
D
10

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

rm -R ~/.node-gyp
Decemvirate answered 5/10, 2018 at 22:21 Comment(0)
O
4

I think delete this directory is better:

rm -rf ~/.node-gyp/
rm -r node_modules/.bin/;
rm -r build/
npm install <your module>
Obstruction answered 15/9, 2019 at 7:57 Comment(0)
Z
4

if you remove your package-lock.json and then run

npm update
npm install
Zealotry answered 3/12, 2020 at 17:23 Comment(0)
H
3

I had the same issue while installing a project which uses the webpack. And i did follow the steps about xcode-select reinstallation but it gave me the same error. For this I did a simple fix, I installed node-sass separately as it was the one giving error.

npm i node-sass

Then ran the installation again using,

npm i

And it worked for me✌️

Sometimes the node packages have older versions which needs to be upgraded as well for a project. For this you get vulnerability related warnings while installation. for this run the following command(it is also mentioned in terminal output),

npm audit fix
Hogg answered 10/3, 2021 at 5:17 Comment(1)
I found switching to the new Dart sass worked for me.Unbent
B
2

I faced similar issue where my MSVS_version was 2019.I tried following steps and issue was resolved.

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

Then

npm config set msvs_version 2017
npm i
Besotted answered 23/4, 2021 at 6:9 Comment(3)
My Os: Windows 10.. so, is it necessary to restart after installing windows-build-tools?Jerriejerrilee
Yess try doing thatBesotted
No need for restart on Win 7. Heartfelt thank you for ending 6 hour odyssey to fix this.Gerthagerti
O
2

This can also occurs if you have Python 3.11 installed, as mentioned here https://mcmap.net/q/153143/-node-gyp-err-invalid-mode-39-ru-39-while-trying-to-load-binding-gyp

Overcharge answered 20/4, 2023 at 11:49 Comment(0)
V
1

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

Vitelline answered 2/1, 2020 at 13:52 Comment(0)
P
1

I ran into this issue from a web development context via node-sass or gulp-sass which uses the gyp library that fails to install. tldr; too old, upgrade to sass which will avoid the gyp issue

Did some deep investigating on the issue. Several people may have ran into this issue because they're attempting to use gulp-sass which depends on node-sass in their development and along the way this gyp issue popped up.

Initially in the gulp-sass installation an error popped up complaining that python2.7 was not installed in my computer. Once I installed that, the gyp issue showed up due to an incompatability of the newest node and gyp. My solution was to use the newest gulp with the newest sass. Hope this helps anyone who arrived here from web development.

Posting answered 28/5, 2023 at 21:28 Comment(0)
S
1

You probably need to change node-sass to sass in your package.json as stated on node-sass's official page (see here):

Warning: LibSass and Node Sass are deprecated. While they will continue to receive maintenance releases indefinitely, there are no plans to add additional features or compatibility with any new CSS or Sass features. Projects that still use it should move onto Dart Sass.

Scaramouch answered 4/6, 2023 at 4:54 Comment(0)
B
0

As described here: 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-dev on my Ubuntu

$ sudo apt install libpq-dev

then try to removing the node_modules and do npm install again.

Note Please 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

Blau answered 2/1, 2020 at 7:57 Comment(3)
npm ERR! code E404 npm ERR! 404 Not Found - GET registry.npmjs.org/libpq-dev - Not foundJugal
It's not an NPM modules @PirAbdul, it's on your machine. Find a match module for your OS, in my case it's Ubuntu. On yours maybe a little different depending on what you use. Please read carrefully.Blau
I run sudo apt install libpq-dev - my issue is fixedMenorca
F
0

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

brew unlink python@2
brew link python
Farron answered 22/3, 2020 at 17:30 Comment(0)
G
0

I had to update to dart-sass, was still using node-sass which is deprecated. https://github.com/sass/dart-sass#from-npm

Groceries answered 1/2, 2022 at 14:43 Comment(0)
A
0

I was facing similar issue while doing npm install for one of existing vuejs app. Initially it complained for missing python. after installing python, i started getting this error - gyp ERR! stack Error: gyp failed with exit code: 1

Later I realized that the project also had package-lock.json. I removed it and did npm install. It worked!!! So if you are facing similar issue, and also have package-lock.json then try removing it.

Athenaathenaeum answered 23/3, 2022 at 16:27 Comment(0)
S
0

I was stuck with this issue for quite long on macOS. For me, on macOS, I had to

  1. Install Python 2.7.x while Python 3 was already installed
  2. Ensure Python 2 path was included in $PATH
  3. Switch CLI. It didn't work in iTerm2, but worked fine on standard macOS terminal

I did install xcode as well, but that didn't have an effect

Selflove answered 28/10, 2022 at 11:7 Comment(0)
G
0

I got the same gyp ERR! error on Ubuntu 22 when I was installing node-heapdump.

To fix it, I run the following command:

 sudo apt install node-gyp
Glidebomb answered 29/1, 2023 at 12:45 Comment(0)
O
0

I fixed this issue by changing the node version.

I use nvm to handle multiple node versions. I was using node v14.x and npm v6.x and I had to change node to 16.x and npm 8.x

I did:

nvm use 16

If you don't have nvm, you need to install it using brew:

brew install nvm

I know there could be multiple fixes for this error but this worked for me.

Later edit: I also switched from node-sass to sass as node-sass is not maintained anymore and the migration is not that complex. You can have a look at how to do this here.

Onega answered 20/2, 2023 at 19:27 Comment(0)
H
0

macOS install gpu.js

Running on MacOS following these install steps:

  1. install nvm curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash then open a new shell session.
  2. nvm install 16
  3. nvm use 16
  4. brew install yarn [OR] npm install --global yarn
  5. yarn add gpu.js
node gpu-test.js

Test file example gpu-test.js:

const { GPU } = require('gpu.js');
const gpu = new GPU();
const multiplyMatrix = gpu.createKernel(function(a, b) {
    let sum = 0;
    for (let i = 0; i < 2; i++) {
        sum += a[this.thread.y][i] * b[i][this.thread.x];
    }
    return sum;
}).setOutput([2, 2]);

const a = new Array(2).fill(new Array(2).fill(1));
const c = multiplyMatrix(a, a);

console.log(a);
console.log(c);

output gpu.js on macOS

Heideheidegger answered 23/3, 2023 at 3:15 Comment(1)
For centos (yum) there were missing libs: 1. sudo yum install libXi-devel mesa-libGL-devel 2. nvm install 18.12.1 3. nvm use v18.12.1 4. sudo yarn add gpu.jsHeideheidegger
W
0

I found a solution: 1、install corresponding version of node-sass;

see:https://www.npmjs.com/package/node-sass

2、install latest version of sass-loader;

see:https://www.npmjs.com/package/sass-loader

3、install python and add into PATH;

4、run npm install;

Wolters answered 19/6, 2023 at 4:27 Comment(0)
F
0

I had the same error in my project. The thing is package.json is already installed and dependencies are defined. I found the solution in this article.

https://sebhastian.com/npm-err-code-1/

It suggests to run npx npm-check-updates to update dependencies one by one. Then run npx npm-check-updates -u to update package.json. Then 'npm install' and it runs fine. No error.

Frimaire answered 21/2, 2024 at 5:50 Comment(0)
T
0

For me I was on

  • M1 mac
  • node version 0.10.48
  • ubuntu official docker image

and the command that caused the error was

npm install -g [email protected]

the fix was to untick "Use Rosetta ..." from Docker and click Apply & Restart

enter image description here

Tollmann answered 15/4, 2024 at 8:52 Comment(0)
S
-1

For MAC ONLY

Step: 1

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

Step: 2

sudo xcode-select --switch /Library/Developer/CommandLineTools/
Sesquicentennial answered 6/11, 2020 at 4:27 Comment(1)
How can this be helpful? Do you mind explaining your solution. You should this command before --switch command above xcode-select --installBucci
H
-1

If you watch some sort of old tutorial and want to install webworker-threads from NPM, you should know that it's a part of Node JS.

const { Worker } = require('worker_threads');

You can see more about differences here https://nodejs.org/api/worker_threads.html

Harken answered 12/1, 2022 at 1:28 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.