unable to solve error code 1 when running"npm install" - npm

when I try to run "npm install" I get errors that I have brought parts of them here:
npm ERR! code 1
npm ERR! git dep preparation failed
npm ERR! command /usr/local/lib/node_modules/node/bin/node
/usr/local/lib/node_modules/npm/bin/npm-cli.js install --force --
cache=/Users/afshinshahpari/.npm --prefer-offline=false --prefer-online=false --
offline=false --no-progress --no-save --no-audit --include=dev --include=peer --
include=optional --no-package-lock-only --no-dry-run
npm ERR! npm WARN using --force Recommended protections disabled.
npm ERR! npm WARN old lockfile
npm ERR! npm WARN old lockfile The package-lock.json file was created with an old
version of npm,
npm ERR! npm WARN old lockfile so supplemental metadata must be fetched from the
registry.
npm ERR! npm WARN old lockfile
npm ERR! npm WARN old lockfile This is a one-time fix-up, please be patient...
npm ERR! npm WARN old lockfile
npm ERR! npm WARN deprecated fsevents#1.2.11: fsevents 1 will break on node v14+ and
could be using insecure binaries. Upgrade to fsevents 2.
after reading few articles , I used many commands like this:
npm cache clean --force
or
npm i --package-lock-only
But none of them fixed the issue, even some of them like "npm audit fix --force" showed other types of errors.
Any advice would be appreciated.

What version of node and npm are you using?
I had the same error, spent hours Googling and trying the same things...
npm cache clean --force
rm -rf node_modules
rm -rf package-lock.json
The error remained...
I ended up downgrading my version of npm to 6.14.15. I was using the latest version of npm which I believe is 7.something. I downgraded to 6.14.15 because that's the one that comes in the stable node.js download.
I don't have the details on why it worked or what's different in the versions but running npm i worked for me after downgrading.

I had same issue
try this, it will solve the issue
npm cache clean --force
rm -rf node_modules
rm -rf package-lock.json
npm install -g npm#6.14.15
npm i

Related

how to solve error code 1 when running npm

I am using Visual Studio Code on MacOS latest version.
I am getting many errors when I try to run npm start that I have posted in a separate question here:
unable to solve error code 1 when running"npm install"
I thought to install all possible modules again to solve the issue when I try to run:
npm i -g npm
I even get errors that part of that is copied here:
ERR! code 1
npm ERR! git dep preparation failed
npm ERR! command /usr/local/lib/node_modules/node/bin/node
/usr/local/lib/node_modules/npm/bin/npm-cli.js install --force --
cache=/Users/afshinshahpari/.npm --prefer-offline=false --prefer-online=false --
offline=false --no-progress --no-save --no-audit --include=dev --include=peer --
include=optional --no-package-lock-only --no-dry-run
npm ERR! npm WARN using --force Recommended protections disabled.
npm ERR! npm WARN old lockfile
npm ERR! npm WARN old lockfile The package-lock.json file was created with an old
version of npm,
npm ERR! npm WARN old lockfile so supplemental metadata must be fetched from the
registry.
npm ERR! npm WARN old lockfile
npm ERR! npm WARN old lockfile This is a one-time fix-up, please be patient...
npm ERR! npm WARN old lockfile
npm ERR! npm WARN deprecated fsevents#1.2.11: fsevents 1 will break on node v14+ and
could be using insecure binaries. Upgrade to fsevents 2.
I tried to fix the issue using this article:
npm ERR! git dep preparation failed when trying to install package.json
but when running "npm audit fix" i get a new set of errors:
npm ERR! code ENOLOCK
npm ERR! audit This command requires an existing lockfile.
npm ERR! audit Try creating one first with: npm i --package-lock-only
npm ERR! audit Original error: loadVirtual requires existing shrinkwrap file
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/afshinshahpari/.npm/_logs/2021-08-16T12_46_15_639Z-debug.log
in order to solve it, I used
npm i --package-lock-only
but no success.
Here's the solution bro try this.
Step 1:
$ npm cache clean --force
Step 2
Delete node_modules by
$ rm -rf node_modules package-lock.json folder
or delete it manually by going into the directory and right-click > delete / move to trash. Also, delete package-lock.json file too.
Step 3
npm install
To start again,
$ npm start
This worked for me. Hopes it works for you too.
PS: If it is still there, kindly check the error it is displaying in red and act accordingly. This error is specific to Node.js environment.

Trying to update to latest NPM version but existence of npx is blocking it

I would like to update to the latest npm version on a mac, so of course I ran
npm install -g npm#latest
but I got the following error message
rm not removing /usr/local/bin/npm as it wasn't installed by /usr/local/lib/node_modules/npm
npm WARN rm not removing /usr/local/bin/npx as it wasn't installed by /usr/local/lib/node_modules/npm
npm ERR! code EEXIST
npm ERR! syscall symlink
npm ERR! path ../lib/node_modules/npm/bin/npx-cli.js
npm ERR! dest /usr/local/bin/npx
npm ERR! errno -17
npm ERR! EEXIST: file already exists, symlink '../lib/node_modules/npm/bin/npx-cli.js' -> '/usr/local/bin/npx'
npm ERR! File exists: /usr/local/bin/npx
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.
Ok, I would like to not run --force to overwrite files recklessly - so how do I get npm to install the latest version in this case?

Craco - Could not resolve dependency error

I am trying to setup TailwindCSS in my Create-React-App project and I am trying to install craco so that I need not eject my CRA
When I run the following command npm install #craco/craco, I get unable to resolve dependency tree error. Below is the detail of the error. What should I do? Thanks
npm install #craco/craco
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: exchange#0.1.0
npm ERR! Found: react-scripts#3.4.3
npm ERR! node_modules/react-scripts
npm ERR! react-scripts#"3.4.3" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react-scripts#"^4.0.0" from #craco/craco#6.1.1
npm ERR! node_modules/#craco/craco
npm ERR! #craco/craco#"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
This works for me
npm install #craco/craco --save --legacy-peer-deps
With the below line you can also set --legacy-peer-deps permanently as a config option. Try to avoid this as you need to see which npm library/libraries in your project is/are having dependency issues.
npm config set legacy-peer-deps true
I've updated my package react-scripts to the latest version 4.x.
by running this command :
npm i react-scripts#latest
then lo and behold, I was able to install craco successfully.
Run this; it worked for me:
npm config set legacy-peer-deps true
Use yarn add, it would solve this for you, you don't need to do anything for the react-scripts version.
I think the error has to do with the dependency tree.
You have react-scripts#3.4.3 but #craco/craco requires react-scripts#4.0.0.
Simply run npm i react-scripts#4.0.0 and create craco.config.js file
i update my react app and then installed craco 5.05v
In my case using node v16.15.1 raising this error.
I resolved it by using node v16.13.1 with fixing the version in package.json
"engines": {
"node": "16.13.1"
},
You can also resolve by using yarn not npm.
Related issue:
Didn't want to upgrade react-scripts
So tried downgrading craco
It worked fine:
Commands that worked fine are below:
npm uninstall -g craco
npm uninstall -g #craco/craco
npm i -g craco#0.0.3
npm i -g #craco/craco#6.4.3
package.json contents:
"react-scripts": "^4.0.3",
"#craco/craco": "^6.4.3",
"craco": "^0.0.3",
If you are changing package.json then do:
npm i
npm install -f
Could help here.

NPM completely broken and won't reinstall after failed upgrade

Mac Catalina 10.15.6
I already had npm installed. I wanted to upgrade so I ran the following.
npm install -g npm
Below is the output:
$name#$names-MacBook-Pro desktop % npm install -g npm
/usr/local/bin/npx -> /usr/local/lib/node_modules/npm/bin/npx-cli.js
/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
npm ERR! code EEXIST npm ERR! syscall symlink npm ERR! path
../../../lib/node_modules/npm/man/man1/npm-bin.1 npm ERR! dest
/usr/local/share/man/man1/npm-bin.1 npm ERR! errno -17 npm ERR!
EEXIST: file already exists, symlink
'../../../lib/node_modules/npm/man/man1/npm-bin.1' ->
'/usr/local/share/man/man1/npm-bin.1' npm ERR! File exists:
/usr/local/share/man/man1/npm-bin.1 npm ERR! Remove the existing file
and try again, or run npm npm ERR! with --force to overwrite files
recklessly.
npm ERR! A complete log of this run can be found in: npm ERR!
/Users/$name/.npm/_logs/2020-10-04T14_41_02_611Z-debug.log
Now all NPM commands fail.
zsh: command not found: npm
Everything from:
npm -v
sudo npm install npm -g
I just used home brew to upgrade NPM and it deleted and reinstalled all the necessary files.
This generally works for me on Mac:
brew upgrade
brew cleanup
brew install npm
(note you'll need the xcode tools if you don't have it - try xcode-select --install or check out this answer.)
Now, try npm install again and see if that changes anything.
Also, see this potentially related answer.

Why I can not run Npm run dev?

Guys can you please help me on this I have trouble run npm run dev for my Laravel Mix. I followed links below but still error exist. Do i have a problem on my OS? I tried to remove node_modules, run npm install --global cross-env. and run NPM install again.
'cross-env' is not recognized as an internal or external command,
https://github.com/JeffreyWay/laravel-mix/issues/478
The error I always get when I ran npm run dev :
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! # development: `cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the # development 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! /Users/baloghdominik/.npm/_logs/2020-02-26T17_05_54_290Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! # dev: `npm run development`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the # dev 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! /Users/baloghdominik/.npm/_logs/2020-02-26T17_05_54_315Z-debug.log
First run
npm install cross-env
npm install
Then run
npm run dev
Simple steps :
npm cache clear --force
delete node_modules and package-lock.json
npm install
npm run dev
rm -rf node_modules
rm package-lock.json yarn.lock
npm cache clear --force
npm install
Basically delete the node_modules folder and package-lock.json file , clear cache and do an npm install. Worked for me.
In my case I had old version of node.js
so I just installed version I need:
sudo npm install n -g
sudo n stable
Or can try use latest:
sudo n latest
If u using nvm, u need use version for project. Commands helped for me:
Use default version node: nvm use system
Remove node_modules rm -rf node_modules and rm -f package-lock.json
Clear cache npm cache clear --force
Finished command npm i