91

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?

JackH
  • 4,613
  • 4
  • 36
  • 61
  • Possible duplicate of [While doing npm install getting an error as "No such file or directory open"](https://stackoverflow.com/questions/52789711/while-doing-npm-install-getting-an-error-as-no-such-file-or-directory-open) – Michael Freidgeim May 10 '19 at 13:11

17 Answers17

135

Try deleting the package-lock.json file.

tantalum
  • 2,354
  • 1
  • 15
  • 22
  • 24
    I have the same issue but there is no package-lock.json – tomwang1013 May 30 '18 at 02:27
  • 2
    Weird. I assumed `package-lock.json` would fix itself instead of giving such a cryptic indirect error, but this indeed fixes that error o_o. – binki Jul 15 '18 at 20:48
  • we get this same thing - deleteing package-lock does "fix" the issue but prevents us from using locks. It has something to do with mapped file system permissions I think. – httpete Aug 17 '18 at 13:29
  • 2
    Nice! can you elaborate on why this is the solution? i mean what is exactly the problem here and why deleting this file is helping? – Sagiv b.g Dec 18 '18 at 17:55
  • Let me begin by stating that **no** elaborate engineering when into this, but here is my guess. According to the docs `package-lock.json` " It describes the exact tree that was generated, such that subsequent installs are able to generate identical trees, regardless of intermediate dependency updates." So there as an issue with that particular version of sails, but that specific version was locked in by package-lock.json. By deleting the file npm can now install an updated version that has the issue fixed.... Again this is just a guess so keep that mind. – tantalum Dec 20 '18 at 16:56
  • 29
    Doesn't deleting package-lock.json defeat the purpose of having package-lock.json? – davidtbernal Aug 14 '20 at 18:12
33

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.

StriplingWarrior
  • 151,543
  • 27
  • 246
  • 315
21

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
coturiv
  • 2,880
  • 22
  • 39
15

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

npm cache verify
Hillgor
  • 151
  • 1
  • 3
15

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
menrodriguez
  • 209
  • 3
  • 5
10

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.

jspru
  • 1,060
  • 1
  • 9
  • 17
  • 1
    Could you give more details as to how you went about this process please? – Leigh Bicknell Oct 03 '19 at 08:18
  • 1
    now i can't remember if there was a specific error that led me to the problemactic package, but there are some troubleshooting steps and tools that might help: First try this: Delete 'Node_modules'. Run 'npm i' again. Check logs for any indication of problems concerning specific packages. helpful commands: npm ls - generate a visual dependency tree (including sub dependencies) https://docs.npmjs.com/cli/ls.html npm audit - find vulnerable dependencies https://docs.npmjs.com/cli/audit Last resort: delete package-lock.json (or yarn lock) and run 'npm i'. – jspru Oct 03 '19 at 19:53
4
  • 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.

Tejas Savaliya
  • 572
  • 7
  • 8
3

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.

Severun
  • 2,893
  • 1
  • 16
  • 22
  • BTW, after doing the above, my package-lock.json files now work. Before I made sure all my dependencies were ordered as such, I no longer have to remove my package-lock.json files to get it to work. – Severun Oct 25 '18 at 20:41
  • Could you provide more details as to how to go about this process? How do you descover which modules depend on which etc? – Leigh Bicknell Oct 03 '19 at 08:20
  • The above worked for a bit and then came back again, after some of my team added more dependencies. One of the problems seems to be that npm installs dependencies asynchronously and depending on how you nest your dependencies, it fails in random places (because of a race condition between the async threads). For example, in the above example, if module C starts installing, then B starts installing, B will fail because it's trying to install C, which is also installing as a result of A. I just could never get npm to work 100% of the time, I switched to yarn, and have not had a problem since. – Severun Oct 08 '19 at 20:20
  • 1
    @LeighBicknell little late reply but for future readers you can use `npm ls name-of-package` which will show you the dependency tree – Mike Harrison Apr 08 '22 at 21:23
3

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

Neha Sharma
  • 449
  • 5
  • 13
3

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.

  • 1
    This seems like a probable cause in certain scenarios. I'm currently working on upgrading a repo from Node v12 to v16, and it's possible a mismatch popped up along the way. – Chris Perry Jun 30 '22 at 22:27
2

I have presented this same error due to npm cache problems. Run

npm install --cache /tmp/empty-cache
fcdt
  • 2,371
  • 5
  • 14
  • 26
1

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
Željko Šević
  • 3,743
  • 2
  • 26
  • 23
0

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

王大拿
  • 1
  • 2
0

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.

Chris Perry
  • 6,666
  • 3
  • 11
  • 21
0

A quick checklist to solve this issue

  • Verify you are in the right directory with a correctly initialised npm project.

  • Verify you are using the correct Node and npm versions for your project then retrying npm i

  • Try deleting package-lock.json and then npm i.Keep in mind simply deleting package-lock.json outright might not work for some cases due to people relying on the lock behaviour, but it can lead you to the root cause.

  • Once you find the root cause and solve it, you can always revert back to the old package-lock.json

  • Verify if you are using any private packages in your package.json. Depending on the package the ~/.npmrc file might be missing or incorrectly configured.

  • Always be wary when deleting and regenerating package-lock.json as it can cause some confusing bugs sometimes.

Issue in my case

  • I was missing the ~/.npmrc file which would throw the npm WARN tar ENOENT: no such file or directory error when running npm i for a project that used private packages.

  • Deleting the package-lock.json and running npm i threw this error.

npm ERR! 404  '@aPrivatePackage@^2.36.0' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404 It was specified as a dependency of 'myProject'
  • At this point it was clear I had to configure my .npmrc for this to work correctly as the private package required doing so.
  • After setting up my .npmrc and restoring the previous lock file npm i then worked correctly.
Omkar Pai
  • 1
  • 2
0

I faced it with this issue when creating new react app via terminal.

For solving this problem;

I've previously installed create-react-app globally. I uninstall the package to ensure npx always uses the latest version of create-react-app.

To uninstall, run this command: npm uninstall -g create-react-app

After that, try to create new react app via npx create-react-app my-react-app

TeachMeJava
  • 640
  • 1
  • 13
  • 35
0

Need to check the following:

  1. .npmrc contains valid credentials & complete list of repos URL to download the required modules
  2. Delete the package-lock.json file
  3. Directory where npm install is being run, make sure it has write permission
Tyler2P
  • 2,324
  • 26
  • 22
  • 31