How to solve npm install error “npm ERR! code 1”
Asked Answered
L

23

83

I'm trying to install Gulp.js and when I write npm install I get this issue:

npm ERR! code 1
npm ERR! path D:\www\wegrow\node_modules\node-sass
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node scripts/build.js
npm ERR! Building: C:\Program Files (x86)\nodejs\node.exe D:\www\wegrow\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp verb cli [
npm ERR! gyp verb cli   'C:\\Program Files (x86)\\nodejs\\node.exe',
npm ERR! gyp verb cli   'D:\\www\\wegrow\\node_modules\\node-gyp\\bin\\node-gyp.js',
npm ERR! gyp verb cli   'rebuild',
npm ERR! gyp verb cli   '--verbose',
npm ERR! gyp verb cli   '--libsass_ext=',
npm ERR! gyp verb cli   '--libsass_cflags=',
npm ERR! gyp verb cli   '--libsass_ldflags=',
npm ERR! gyp verb cli   '--libsass_library='
npm ERR! gyp verb cli ]
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | win32 | ia32
npm ERR! gyp verb command rebuild []
npm ERR! gyp verb command clean []
npm ERR! gyp verb clean removing "build" directory
npm ERR! gyp verb command configure []
npm ERR! gyp verb check python checking for Python executable "python2" in the PATH
npm ERR! gyp verb `which` failed Error: not found: python2
npm ERR! gyp verb `which` failed     at getNotFoundError (D:\www\wegrow\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (D:\www\wegrow\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (D:\www\wegrow\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at D:\www\wegrow\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at D:\www\wegrow\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at D:\www\wegrow\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:194:21)
npm ERR! gyp verb `which` failed  python2 Error: not found: python2
npm ERR! gyp verb `which` failed     at getNotFoundError (D:\www\wegrow\node_modules\which\which.js:13:12)
npm ERR! gyp verb `which` failed     at F (D:\www\wegrow\node_modules\which\which.js:68:19)
npm ERR! gyp verb `which` failed     at E (D:\www\wegrow\node_modules\which\which.js:80:29)
npm ERR! gyp verb `which` failed     at D:\www\wegrow\node_modules\which\which.js:89:16
npm ERR! gyp verb `which` failed     at D:\www\wegrow\node_modules\isexe\index.js:42:5
npm ERR! gyp verb `which` failed     at D:\www\wegrow\node_modules\isexe\windows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:194:21) {
npm ERR! gyp verb `which` failed   code: 'ENOENT'
npm ERR! gyp verb `which` failed }
npm ERR! gyp verb check python checking for Python executable "python" in the PATH
npm ERR! gyp verb `which` succeeded python C:\Python39\python.EXE
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Command failed: C:\Python39\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
npm ERR! gyp ERR! stack   File "<string>", line 1
npm ERR! gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
npm ERR! gyp ERR! stack                       ^
npm ERR! gyp ERR! stack SyntaxError: invalid syntax
npm ERR! gyp ERR! stack
npm ERR! gyp ERR! stack     at ChildProcess.exithandler (node:child_process:326:12)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:365:28)
npm ERR! gyp ERR! stack     at maybeClose (node:internal/child_process:1067:16)
npm ERR! gyp ERR! stack     at Socket.<anonymous> (node:internal/child_process:453:11)
npm ERR! gyp ERR! stack     at Socket.emit (node:events:365:28)
npm ERR! gyp ERR! stack     at Pipe.<anonymous> (node:net:661:12)
npm ERR! gyp ERR! System Windows_NT 10.0.19042
npm ERR! gyp ERR! command "C:\\Program Files (x86)\\nodejs\\node.exe" "D:\\www\\wegrow\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
npm ERR! gyp ERR! cwd D:\www\wegrow\node_modules\node-sass
npm ERR! gyp ERR! node -v v16.1.0
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok
npm ERR! Build failed with error code: 1

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\wbalu\AppData\Local\npm-cache\_logs\2021-05-05T10_38_29_779Z-debug.log

I have formatted my computer. Everything was working before. And now when I try to install it, that's what pops up. I have tried reinstalling Node.js, but it didn't help. What should I do?

Lab answered 5/5, 2021 at 10:45 Comment(2)
You have a program written in the Python2 language and you are trying to run it with Python3: a related, but different, language. This is not a problem with node.js, and has nothing to do with Git.Metalline
I have downloaded python27 and added it to PATH, and it still doesn't work :/ Same error. I don't know if i did something wrong or sth.Bloodyminded
A
72

If your Node.js version is very recent, try downgrading. The stable version 14.16.1 worked.

Atiana answered 11/5, 2021 at 13:2 Comment(7)
This was definitely issue for me. I went through a bunch of hoops, and downgrading node is what worked. 14.x is what is currently recommended for most people. Yarn forces me up to 16.x. In homebrew, you can brew install node@14 brew unlink node brew link node@14 to get back to 14 or to switch between them.Concerning
thanks @Atiana this worked in my apple-silicon scenario, using brew as @Concerning shows, however instead of unlink/link I simply alias each of npm, npx, node alias npm14='/opt/homebrew/Cellar/node@14/*/bin/npm' and using these works, I'm sure there'll be an issue with global node_modules path I've yet to resolve.Underrate
download link : nodejs.org/dist/v14.16.1Fanechka
solved my "npm install" problem; thank you.!Obstetrician
I had the same problem, then i did downgrade the node version from18 to 16, then it worked perfectly.Hendricks
This solved it for me, too. FYI, I highly recommend Node Version Manager for easily installing / switching between node versions. Here's a straightforward setup guide: freecodecamp.org/news/node-version-manager-nvm-install-guide.Paries
omg thank you, searched 2h for this answer. I had Node 20.4 and downgraded to 18.16 and it finally workedTumbrel
H
51

Downgrading Node.js is one option, but I don't like the idea of downgrading Node.js just because one package throws an error. In my opinion, it would be a better approach to find out which package is causing the error and then fix it.

The quick solution

In the line after npm ERR! code 1, you should be able to see npm ERR! path.... In my case the path indicates that there is a problem with the node-sass npm package:

npm ERR! code 1
npm ERR! path /home/gignu/GitHub/Movie-Subtitles/node_modules/node-sass
npm ERR! command failed

Now remove this npm package from package.json and see if the installation works. If it works you've found the culprit! In my case, all I had to do to fix it was to upgrade node-sass to the latest version.

// package.json with the outdated dependency

"node-sass": "^4.14.1",
// package.json with the updated dependency

"node-sass": "^7.0.1",

The slow solution

If the previous solution doesn't work for you I would go with @Andrew Fair's solution:

I took out the entire dependencies portion in my package.json file and just started working my way through installing one at a time.

To do this, simply copy the whole dependencies section and devDependencies section from package.json and paste it into a text editor as a backup. Then delete all your dependencies and try adding back one dependency at a time. You can also add back several dependencies at a time if you have a lot of them. Each time, run npm i and see if it throws an error. Once you've found out which dependency is causing the error, try to upgrade that dependency to a newer version and then run npm i --force!

If that doesn't work, try replacing the bad npm package with another one or look on their GitHub repository for solutions.

Homogenetic answered 30/1, 2022 at 13:43 Comment(1)
This solution worked for me, but only with node-sass 8.0.0 (with node v18.16 and python 3)Hectogram
H
13

Try

npm cache clean --force

Delete folder node_modules and file package-lock.json.

npm i
Hydrofoil answered 26/7, 2021 at 15:9 Comment(2)
this worked for me and seems to be a much better solution to me than downgrading anythingParthinia
stackoverflow cheat: search random question related to npm, suggest this.Dromond
S
6

When I try to run the npm install command in an older project, I faced the same issues and I resolved it by updating the dependencies in package.json to the latest versions by following these steps:

  1. delete folder node_modules folder and file package-lock.json

  2. install npm-check-updates globally, to update all packages to a new major version

    run npm install -g npm-check-updates

  3. run ncu -u to update dependencies in package.json to latest version

    Note: you can use npm update, but npm update doesn't update to latest version

  4. run npm install

Sextodecimo answered 16/5, 2022 at 8:40 Comment(1)
this breaks everything :DTradeswoman
V
5

I ran into this issue as well. After looking over my setup, I saw nothing wrong and deleted the cache and deleted package-lock and still no success.

This was an older website and I tried using update, etc. to no avail.

So I took out the entire dependencies portion in my package.json file and just started working my way through installing one at a time.

It works!

Apparently almost all of the versions were a major update behind which was too much for it to update.

Vizier answered 3/10, 2021 at 15:2 Comment(1)
Thought it was just me but running npm install multiple times with multiple system restarts (or vscode restarts) has had some success... (different modules from last time) ....still some issues but possibly unrelated.Liturgy
R
4

I had faced the same issue after upgrading Angular. So I tried multiple steps to resolve it. Some of the steps are mentioned below.

  1. try with deleting package-lock.json file and node_module folder then run

    npm cache clean --force
    

    And try npm i again to install packages. If it is still not working, check step 2.

  2. Check the Node.js version and npm version to see if both versions are compatible. In my case, I was using Node.js v14.15.0 and npm v8.1.6, so I uninstalled the npm with the below command and installed Node.js again to make the Node.js and npm versions in sync.

    npm uninstall npm -g
    

And this works for me.

Reive answered 15/2, 2022 at 11:52 Comment(1)
After lot of struggle, this solution worked for me! npm and nodejs versions are mismatching and above solution fixed it.Scrivens
H
2

Maybe try yarn install. It works for me.

Heartbreaking answered 21/5, 2022 at 22:43 Comment(0)
S
2
  1. delete package-lock.json and node_modules if exists
  2. npm cache clean --force
  3. npm install or npm install --legacy-peer-deps
Shanghai answered 28/2, 2023 at 16:24 Comment(1)
This solution also works when a similar error is shown, e.g. when downgrading an Angular app to a lower versionZaidazailer
S
2
npm remove node-sass
npm add sass

It's working for me.

Spontaneity answered 31/10, 2023 at 2:7 Comment(0)
I
1

The answer can be found here. It is the same issue: https://mcmap.net/q/260072/-i-cannot-run-any-project-because-of-gyp-error-how-can-i-fix-this-npm-err-gyp-verb-cli

With most of the operating systems removing python2 this is a common issue for most projects. It definitely affected 4/5 of my recent projects after upgrading to current Linux/Debian Stable which removed python2.

The solution is for system to start using python3 and in order to do that you need to..

Solution/Solved is:

node-sass is actually at fault. Python2 is required until version 6.0.0. Normally you would upgrade to latest 7.0.3 but node-sass is currently obsolete, so we will swap to sass project.

yarn remove node-sass
yarn add sass

I've given more details on reasoning why here, or alternative dart-sass if you use "render() and renderSync() functions".:

Solved-ERR!gyp-info-using-node-gyp-3.8.0-gyp-verb-which-failed-Error-not-found-python2

Affected:

  • node.js /react web apps
  • Elixir/Phoenix assets
  • Android apps
  • Vue.js projects
Inger answered 25/10, 2022 at 21:39 Comment(0)
B
0
npm install -g npm@latest

seemed to solved it for me

Beatup answered 9/9, 2022 at 20:19 Comment(0)
A
0

for me was downgrading not an option as it worked for me on my mac with node 16.17 and also on a multipass vm with ubuntu but then in my docker ubuntu i ran into this error.

So there must have been a different issue. For me it was missing build-essential package.

sudo apt-get update
sudo apt-get install build-essential
Arteriole answered 10/10, 2022 at 7:15 Comment(0)
N
0
  1. Open package.json and cut all under dependencies to a text file
  2. Now run npm install without anything in dependencies If this works, all fine
  3. Now add back the dependencies, one by one from the top
  4. After each new dependency (don't forget to remove the , comma in the end), run npm install.
  5. Once you have run this many times enough, you will see at which package it breaks.
  6. Now let's google that package and see how it can be updated or if we can live without it.

This is how I solved it, full story here https://mcmap.net/q/260073/-npm-warn-deprecated-email-160-protected

Needle answered 23/12, 2022 at 9:18 Comment(0)
C
0

I recently cloned a git repository that contained a simple portfolio site. It used npm to manage packages and I had to run npm install in order to install all the dependencies. This was the error I received.

npm ERR! code 1
npm ERR! path PATH\node_modules\lmdb-store
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node-gyp-build 

I my case upgrading all the dependencies to the latest version solved the issue.

Cowboy answered 26/12, 2022 at 10:22 Comment(0)
M
0
  • Node version 14.16.1(LTS) is supported with morgan.
  • You can use NVM(Node version manager) to control the node version.
  • After installing NVM change the node version using following commands:

nvm install 14.16.1
nvm use 14.16.1
Manzanilla answered 28/12, 2022 at 17:59 Comment(0)
B
0

If your project has yarn.lock file, then should use yarn package manager. to do that follow:-

  1. type/run npm install --global yarn in cmd(command prompt) or terminal.
  2. restart the terminal
  3. run yarn -v to check whether it installed properly
  4. open terminal with your project directory and run yarn install.
Biysk answered 4/1, 2023 at 5:48 Comment(0)
S
0

If your Node.js version is very recent, try downgrading and if you are using the latest Angular Framework version of v15.0.0, then the minimum stable version of the node is 14.20 worked. So install this version, the link is provided below: Node version 14.20.0 download link

Shaffer answered 8/6, 2023 at 7:25 Comment(0)
H
0

I tried all of the above comments. The only one that worked for me was deleting and reinstalling all the dependencies and devDependencies. After doing that I still had one error related to "gulp-strip-debug", and downgrading that to version 3.0.0 fixed the final error.

Hormonal answered 28/9, 2023 at 12:57 Comment(0)
P
0

If the error related to libxmljs, then try to install the latest version using npm i [email protected]

Photocurrent answered 9/1, 2024 at 13:56 Comment(0)
A
0

For me just deleting the node modules and then doing npm install worked

Alsatia answered 5/2, 2024 at 3:47 Comment(0)
N
0

I agree Downgrading Node.js is an option, but I don't like the idea of ​​downgrading Node.js just because a package throws an error. IMO it would be a better approach to find out which package is causing the error and then fix it.

In my case the library that generated the error was sharp, I just updated that one from "sharp": "^0.29.2", to "sharp": "^0.30.0",

Neuroticism answered 15/7, 2024 at 15:48 Comment(0)
K
-2

Try

npm install --python=python2.7`

Alternatively

--python=path to your Python executable
Kahlil answered 5/5, 2021 at 11:40 Comment(1)
npm config set python and your python executable? And then npm install?Kahlil
H
-2

Try cnpm. It works for me.

npm install -g cnpm --registry=https://registry.npmmirror.com
cnpm install
Howes answered 8/3, 2022 at 22:12 Comment(1)
What is "cnpm"? Why should it be used? What is the advantage? Please respond by editing (changing) your answer, not here in comments (without "Edit:", "Update:", or similar - the answer should appear as if it was written today).Sponsor

© 2022 - 2025 — McMap. All rights reserved.