NPM "ENOENT: no such file or directory error" when installing Sails.js dependencies with Node 8.9.4 LTS - node.js

I recently upgraded my computer and with it, to the latest LTS version of Node and NPM:
Node.js 8.9.4
NPM 5.6.0
I have a Sails.js 0.12.14 application for which I'm trying to install NPM dependencies with npm install but when I do that, I get the following errors:
➜ web-service git:(feature/auth) ✗ npm install
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/pako-660dbb41/package.json'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/pako-660dbb41/README.md'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/pako-660dbb41/LICENSE'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/pako-660dbb41/index.js'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/pako-660dbb41/CHANGELOG.md'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/lodash-6e6c9f2a/fp/camelCase.js'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/lodash-6e6c9f2a/fp/uniqueId.js'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/lodash-6e6c9f2a/fp/bindKey.js'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/lodash-6e6c9f2a/fp/unnest.js'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/lodash-6e6c9f2a/fp/bindAll.js'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/lodash-6e6c9f2a/fp/unset.js'
// a bunch of similar Lodash errors removed from here
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/lodash-6e6c9f2a/fp/T.js'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/lodash-6e6c9f2a/fp/zipWith.js'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/lodash-6e6c9f2a/fp/lastIndexOfFrom.js'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: oauth-sign#0.8.2 (node_modules/oauth-sign):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: Cannot cd into '/Users/Nag/Code/project/web-service/node_modules/.staging/oauth-sign-b13c86db'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: mkdirp#0.5.1 (node_modules/mkdirp):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: Cannot cd into '/Users/Nag/Code/project/web-service/node_modules/.staging/mkdirp-c94c8047'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: minimist#0.0.8 (node_modules/mkdirp/node_modules/minimist):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: Cannot cd into '/Users/Nag/Code/project/web-service/node_modules/.staging/minimist-ba966a6e'
npm ERR! path /Users/Nag/Code/project/web-service/node_modules/.staging/sails-02afd14e/node_modules/#sailshq/body-parser
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename '/Users/Nag/Code/project/web-service/node_modules/.staging/sails-02afd14e/node_modules/#sailshq/body-parser' -> '/Users/Nag/Code/project/web-service/node_modules/.staging/#sailshq/body-parser-6d1e8405'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/Nag/.npm/_logs/2018-01-22T14_40_13_889Z-debug.log
I can't seem to figure out what's going on and can't find suitable answers anywhere else online. I even ran npm cache clean --force, rm -rf node_modules and retried with similar errors. It seemed to work fine when I was on Node ~6 but after upgrading to Node 8.9.4 and NPM 5.6.0, it just won't install my dependencies. How can I resolve this?

Try deleting the package-lock.json file.

For me, it turned out these errors were hiding the real underlying problem, which was that my credentials for a third-party npm repository (azure devops) had expired. I had to re-run vsts-npm-auth -config .npmrc to update the token in my .npmrc file.

No permission, no internet issue, it's just a general issue of npm.
I solved the problem with yarn.
yarn install
Or you can use no-optional flag.
npm install --no-optional

It may be a problem with the cache, try to verify the cache.
npm cache verify

In my case, I tried deleting package-lock.json, clearing and verifing the npm cache, removing node_modules, even stopping the antivirus (W10 machine) and was still getting this error.
I somehow fixed it by running npm update before npm install, which creates a new package-lock.json:
del /f package-lock.json
rd /s /q node_modules
npm cache clean
npm cache verify
npm update
npm install

Deleting and regenerating 'package-lock.json' usually solves this issue however that's inherently risky because you will likely be upgrading multiple packages at a time.
In my case it turned out that there was one specific package version that package-lock.json was referencing, that was 5 levels deep in the dependency. That version no longer existed at the npm registry so it caused the install to break. I had to find which package was pulling in this dependency and upgrade that one to resolve the issue.

Just delete package-lock.json file and then install package(s) you want. All will work.

Delete node_modules
Just delete package-lock.json file and then install packages you want with npm install . All will work.
rm -rf node_modules
rm package-lock.json
npm install
If the issue still persists check if you have a global version of any of the packages installed.
This can happen if you have a global version of a package that clashes with a local version of a package.

I was struggling with this for awhile, and it seems be be related to the following.
Let's say you have 3 modules, A, B and C
Module A includes B and C directly
Module B also includes module C, in it's package.json dependencies.
If your package.json dependencies in module A look like the following:
"dependencies": {
"C": "^1.0.0",
"B": "^1.1.0"
}
You will get the above error you mentioned, ENOENT, blah, blah in .staging
If on the other hand you include the module with the nested include first like:
"dependencies": {
"B": "^1.1.0",
"C": "^1.0.0"
}
The error goes away. This seems like a bug in npm with nested dependencies, and the error messages and logs were not very descriptive. Check your dependency tree and see if you have the described case, if so, that is your issue.

Beside removing package-lock.json I had to remove node_modules so package-lock.json could be generated in the right way
rm -rf node_modules
rm package-lock.json
npm i

I have presented this same error due to npm cache problems. Run
npm install --cache /tmp/empty-cache

This happened to me when I was on Node.js 12 attempting to run npm install against a package-lock.json generated using Node.js 16.
Switching back to Node.js 16 resolved the issue:
nvm use 16
Of course, deleting the package-lock.json would have also resolved the issue for me.

If you dont have package-lock.json or package.json under your working folder, call npm init first.

Checkout package-lock.json from upstream and re-run npm install
I'm dealing with this issue right now, and it seems to have something to do with the way package-lock.json gets generated.
The problem finally resolved itself when I checked out package-lock.json from my team's upstream repository and re-ran npm install.

Related

npm install not working: "npm ERR! code ERR_SSL_WRONG_VERSION_NUMBER"

I can't install modules for my react app, when i run npm i it does this:
npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion#1, but package-lock.json was generated for lockfileVersion#2. I'll try to do my best with it!
npm WARN tar ENOENT: no such file or directory, open 'C:\Users\marco\Code\backend\node_modules\.staging\setprototypeof-b857a2ac\package.json'
npm WARN tar ENOENT: no such file or directory, open 'C:\Users\marco\Code\backend\node_modules\.staging\setprototypeof-b857a2ac\index.d.ts'
npm WARN tar ENOENT: no such file or directory, open 'C:\Users\marco\Code\backend\node_modules\.staging\setprototypeof-b857a2ac\index.js'
npm WARN tar ENOENT: no such file or directory, open 'C:\Users\marco\Code\backend\node_modules\.staging\setprototypeof-b857a2ac\LICENSE'
npm WARN tar ENOENT: no such file or directory, open 'C:\Users\marco\Code\backend\node_modules\.staging\rc-5aecd98b\test\ini.js'
npm WARN tar ENOENT: no such file or directory, open 'C:\Users\marco\Code\backend\node_modules\.staging\setprototypeof-b857a2ac\README.md'
npm WARN tar ENOENT: no such file or directory, open 'C:\Users\marco\Code\backend\node_modules\.staging\rc-5aecd98b\test\nested-env-vars.js'
npm WARN tar ENOENT: no such file or directory, open 'C:\Users\marco\Code\backend\node_modules\.staging\rc-5aecd98b\test\test.js'
npm WARN tar ENOENT: no such file or directory, open 'C:\Users\marco\Code\backend\node_modules\.staging\term-size-f230f088\vendor\windows\term-size.exe'
npm WARN tar ENOENT: no such file or directory, open 'C:\Users\marco\Code\backend\node_modules\.staging\ast-types-5383d6cc\def\type-annotations.js'
npm WARN tar ENOENT: no such file or directory, open 'C:\Users\marco\Code\backend\node_modules\.staging\ast-types-5383d6cc\def\typescript.js'
npm WARN backend#1.0.0 No description
npm WARN backend#1.0.0 No repository field.
npm ERR! code ERR_SSL_WRONG_VERSION_NUMBER
npm ERR! errno ERR_SSL_WRONG_VERSION_NUMBER
npm ERR! request to https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz failed, reason: 4376:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:308:
npm ERR!
I tried reinstalling npm and it does the same thing. I tried with another project and I'm getting the same error. I found another question where someone had the same problem but noone replied. I even tried to set the npm registry to http://registry.npmjs.org instead of https://registry.npmjs.org, and setting the strict-ssl option to false, but it still won't work.
My npm version is 6.14.13 and my node version is v14.17.1.
Any help?
P.S.: I'm not using a proxy
Quick solution would be to delete node_modules and package-lock.json, so that when you reinstall the packages, they get installed with the lockfileVersion#1 instead of lockfileVersion#2.
I wouldn't suggest that solution though, as if you work in a team you would be forcing the others to do the same in order to fix it.
The problem is the npm version v6.x.x supports lockfileVersion#1 while v7.x.x supports lockfileVersion#2.
So a better solution would be to simply update your npm version to a v7 and higher.
Here you can find an interesting related discussion about it: Is there any way to fix package-lock.json lockfileVersion so npm uses a specific format?

how to get the dependencies of a project with a package-lock.json but no package.json?

I have a project with a package-lock.json but no package.json.
When I run npm install I get the following:
npm WARN saveError ENOENT: no such file or directory, open '/home/neubert/myproject/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/home/neubert/myproject/package.json'
npm WARN myproject No description
npm WARN myproject No repository field.
npm WARN myproject No README data
npm WARN myproject No license field.
up to date in 0.279s
found 0 vulnerabilities
Any ideas how I can make it so that the deps in the package-lock.json are downloaded, even if package.json isn't present?
Well my first thought would be to run
npm rebuild
If you have installed previously it will rebuild all the packages and they will print out on your screen. Then its just a matter of adding them back to a package.js
here is a link to npmjs.com and their cli commands... its handy. i have it bookmarked in my cheat sheets

Getting error: "saveError ENOENT: no such file or directory, open '.../package.json'

I am attempting to install newsapi via the command: npm install newsapi --save.
That installs two dependent packages (core-js and node-fetch) as well as newsapi itself. I run the command in my project folder. I have no issues with core-js and node-fetch, but I get the following warnings regarding newsapi.
npm WARN saveError ENOENT: no such file or directory, open 'Users/user_name/project/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 'Users/user_name/project/package.json'
npm WARN project No description
npm WARN project No repository field.
npm WARN project No README data
npm WARN project No license field.
After the installation, package-lock.json is created in my project folder and Users/user_name/project/node-modules/newsapi/package.json does exist. I don't know why the installation asks me to open Users/user_name/project/package.json. Why would it be in my project folder and not in the module's folder?
I tried solutions I read in other threads including deleting package-lock.json and retrying the installation and using npm init. Neither of those methods worked.
I also tried copying and pasting package.json to the project folder (because the warnings prompt me to open Users/user_name/project/package.json) but that did not solve my problems either.
How can I successfully install the module?

npm install from tgz created with npm pack

I've created a .tgz file with npm pack. When trying to install it npm prints out the following error:
D:\tmp>npm install package-0.0.1.tgz
npm WARN saveError ENOENT: no such file or directory, open 'D:\tmp\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 'D:\tmp\package.json'
npm WARN tmp No description
npm WARN tmp No repository field.
npm WARN tmp No README data
npm WARN tmp No license field.
It looks like npm for some reason does not extract the contents of my .tgz package, meaning all the .js files, package.json etc. although everything is there. Apparently it only tries to install the dependencies listed in my package.
Should it really work this way or I'm doing something wrong?
This error means you are not in a directory that has a package.json file and you are using the command that installs a package as a dependency into an existing, (local) npm project's package.json.
To install your package globally (just to test if it can be installed):
npm install -g package-0.0.1.tgz
Or, if you want to install/add it as a dependency to some other npm project (like a test harness), first make sure that npm project has a package.json, and then :
test-harness-dir> npm install package-0.0.1.tgz

npm ERR! Refusing to delete / code EEXIST

I'm just running a simple npm install and i get this error.
npm ERR! path /Users/jasonazoulay/Desktop/fabrick.io/delegation/node_modules/#angular/cli/node_modules/webpack/node_modules/yargs/node_modules/os-locale/node_modules/execa/node_modules/cross-spawn/node_modules/.bin/which
npm ERR! code EEXIST
npm ERR! Refusing to delete /Users/jasonazoulay/Desktop/fabrick.io/delegation/node_modules/#angular/cli/node_modules/webpack/node_modules/yargs/node_modules/os-locale/node_modules/execa/node_modules/cross-spawn/node_modules/.bin/which: is outside /Users/jasonazoulay/Desktop/fabrick.io/delegation/node_modules/#angular/cli/node_modules/webpack/node_modules/yargs/node_modules/os-locale/node_modules/execa/node_modules/cross-spawn/node_modules/which and not a link
npm ERR! File exists: /Users/jasonazoulay/Desktop/fabrick.io/delegation/node_modules/#angular/cli/node_modules/webpack/node_modules/yargs/node_modules/os-locale/node_modules/execa/node_modules/cross-spawn/node_modules/.bin/which
npm ERR! Move it away, and try again
This is the first time I get this error and I don't know what to do.
Steps
Delete the node_modules directory completely.
Run npm install again.
This should help.
This was how I solved mine after 'googling' around...
Navigate to the directory your node was installed in
rename your npm.cmd and npm files
Try run the installation again
If successful..delete the files you renamed earlier npm and npm.cmd
if not, :( :(
The cli commands here...in case you don't want to be renaming and stuffs
cd %ProgramFiles%\nodejs
ren npm.cmd npm2.cmd
ren npm npm2
npm2 install npm#latest -g
del npm2
del npm2.cmd
Rolf-schmidiger
Try running npm update -g npm then run npm i again.
If that doesn't work maybe npm cache clean helps.
If that doesn't work either you should consider removing the node_modules folder in your application and running npm i again.
If you still have no luck, I suggest removing the package-lock.json and the node_modules folder before running npm i.
For windows users (specific to windows 10) this must solve the problem.
Goto this folder:
C:\Users\[UserName]\AppData\Roaming\
delete or rename the npm and npm-cache folders.
This has fixed my problem in Windows.
I got this problem on Linux (npm is the current latest 5.6.0), because I created a tgz archive, and I needed to --dereference some symlinks (see man tar) when creating a tgz archive (which was them copied to VM for testing). This way a lot of symlinks in node_modules/.bin also became regular files.
npm says in the error message, .e.g.
npm ERR! Refusing to delete /path/to/node_modules/.bin/jest: is outside /path/to/node_modules/jest and not a link
This worked for me
npm install -g --force gatsby-cli
Thanks
I had a similar issue but was because initially the project was installed with
yarn install
Then when I tried to install dependencies using
npm install
I caught this same error. So ensure to use only one: yarn or npm. I fixed it by adding my dependency with
yarn add <vendor_name>
but the same works if you use npm instead, you need to add a dependency.
Uninstall node.js from control panel
Delete below folders
C:\Program Files (x86)\Nodejs
C:\Program Files\Nodejs
C:\Users\{User}\AppData\Roaming\npm (or %appdata%\npm)
C:\Users\{User}\AppData\Roaming\npm-cache (or %appdata%\npm-cache)
C:\Users\{User}\.npmrc (and possibly check for that without the . prefix too)
C:\Users\{User}\AppData\Local\Temp\npm-*
Install node.js again
I had a similar error(mine is not #angular),
resolved by deleting and reinstalling node with installer.
I had the same problem and it turned out the problem was that a stray instance of npm was running somewhere in the background at the same time I was trying to do the install (it was Webpack's npm run serve, to be precise).
Stopping the running instance resolved the problem.
I had a similar problem and what seems to have worked is to uninstall npm and reinstall it, making sure to be logged in as the correct user for the reinstall. I think I previously installed npm as root, but was updating a package as a regular (sudo) user.
I had this problem when working on a virtual, encrypted disk.
Moving the project to a regular disk solved the problem.
I the same error but when I was trying to update module "cordova" to version 9. I fixed it by forcing the install with --force. The npm command I used:
npm i -g --force cordova#9
I downgraded my node version to 10 with nvm, and it installed a newer version of npm (v6) during the process. After that, the package was installed w/o errors. So it's either npm or node version.
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
> puppeteer#13.1.3 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 commander#8.3.0: wanted: {"node":">= 12"} (current: {"node":"10.19.0","npm":"6.14.4"})
npm WARN notsup Not compatible with your version of node/npm: commander#8.3.0
...
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/mermaid-cli#8.13.10
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.

Resources