How to Solve Npm Install Error “Npm Err! Code 1”
I'm Trying to Install Gulp and When I Write Npm Install I Got This Issue: Npm Err! Code 1 Npm Err! Path D: \Www\Wegrow\Node_Modules\Node-Sass Npm Err! Command...
I'm trying to install gulp and when I write npm install I got 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 node-gyp@3.8.0
npm ERR! gyp info using node@16.1.0 | 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. I don't know what should I do.
9 Answers
If your Node version is very recent, try downgrading. Stable version 14.16.1 worked.
Downgrading Node is one option but I don't like the idea of downgrading Node 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.
try
npm cache clean --force
Delete node_modules and package-lock.json
npm i
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 dependecies 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 to much for it to update.
I had faced the same issue after upgrading angular, So I tried multiple steps to resolve it. Some of the steps are mentioned below.
- 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 still not working check step 2
- Check nodeJs version and npm version if both versions are compatible. In my case, I was using node v14.15.0 and npm v8.1.6, so I uninstalled the npm with the below command and installed the node js again to make node and npm version in sync.
npm uninstall npm -g
and this works for me.
When I try to run npm install command in older project, I faced the same issues and I resolved it by updating the dependencies in package.json to latest version by following the steps:
delete node_modules and package-lock.json
install npm-check-updates globally, to update all packages to a new major version
run
npm install -g npm-check-updatesrun
ncu -uto update dependencies in package.json to latest versionnote: you can use
npm update, but npm update doesn't update to latest versionrun
npm install
Maybe try yarn install. It works for me.
Try
npm install --python=python2.7.
It should work.
EDIT: Alternatively, --python=path to your python executable
try cnpm,it works for me
npm install -g cnpm --registry=
cnpm install