In my case, when trying to install for example the program mermaid-cli
, and with npm being already installed,
npm install @mermaid-js/mermaid-cli
threw the error in question.
When I added --force
, the output was just shortened, but the same error:
$ sudo npm install @mermaid-js/mermaid-cli --force
npm WARN using --force I sure hope you know what you are doing.
npm WARN enoent ENOENT: no such file or directory, open '/home/MY_USER/package.json'
npm WARN MY_USER No description
npm WARN MY_USER No repository field.
npm WARN MY_USER No README data
npm WARN MY_USER No license field.
npm ERR! code EEXIST
npm ERR! path /home/MY_USER/node_modules/npm/node_modules/.bin/rimraf
npm ERR! Refusing to delete /home/MY_USER/node_modules/npm/node_modules/.bin/rimraf: is outside /home/MY_USER/node_modules/npm/node_modules/rimraf and not a link
npm ERR! File exists: /home/MY_USER/node_modules/npm/node_modules/.bin/rimraf
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! /root/.npm/_logs/2022-02-03T13_41_52_634Z-debug.log
I then followed the accepted answer that says that you only need to remove and install npm
again and therefore removed the directory node_modules
from my home
directory where it was installed.
Yet, I still ran into the error when running npm install
:
$npm install
npm WARN saveError ENOENT: no such file or directory, open '/home/MY_USER/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/home/MY_USER/package.json'
npm WARN MY_USER No description
npm WARN MY_USER No repository field.
npm WARN MY_USER No README data
npm WARN MY_USER No license field.
up to date in 0.865s
found 0 vulnerabilities
The easy fix for this was to just install the program with npm
again when npm
'node_modules are removed! I happened to find out about by entering the command although npm
's node_modules
were removed. Ran through.
Logs:
$npm install @mermaid-js/mermaid-cli
> [email protected] install /home/MY_USER/node_modules/puppeteer
> node install.js
Downloading Chromium r950341 - 142 Mb [====================] 100% 0.0s
Chromium (950341) downloaded to /home/MY_USER/node_modules/puppeteer/.local-chromium/linux-950341
npm WARN saveError ENOENT: no such file or directory, open '/home/MY_USER/package.json'
npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":">= 12"} (current: {"node":"10.19.0","npm":"6.14.4"})
npm WARN notsup Not compatible with your version of node/npm: [email protected]
...
npm WARN MY_USER No description
npm WARN MY_USER No repository field.
npm WARN MY_USER No README data
npm WARN MY_USER No license field.
+ @mermaid-js/[email protected]
added 147 packages from 94 contributors and audited 147 packages in 26.338s
10 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
Wrap up:
If npm install
fails, install whatever program you like or dislike, but install one program with the npm
command even if you just have removed npm
's node_modules
directory. It will download the node_modules
again and in my case, the program worked.
sudo npm install
?npm install