16

When I am running the command npm install npm@latest -g I am getting below error :-

npm WARN tar zlib error: unexpected end of file
npm ERR! cb() never called!

npm ERR! This is an error with npm itself. Please report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\dk\AppData\Roaming\npm-cache\_logs\2018-04-10T03_25_52_880Z-debug.log

i googled it and tried so many things,nothing worked.

F11
  • 3,545
  • 12
  • 42
  • 76

3 Answers3

39

To anyone stumbling upon this question, if you are facing the same error message on npm install, then npm install --no-package-lock solved it for me.

As suggested in the referenced Github issue in Mohit Mutha's comment above, this is especially true if the command is ran in a CI/CD pipeline, or in my case, in Docker.

EDIT: Reason being is that the package-lock.json file already exists in your Docker image or CI pipeline

Full details

Anas Tiour
  • 1,148
  • 1
  • 15
  • 29
  • 1
    Confirming positive use of the flag on gitlab's pipeline for an ng v6 project. – 4F2E4A2E Feb 19 '20 at 17:11
  • 1
    in my case ( jenkins CI ), workspace was corrupted. cleaning the workspace helped. – chandu Nov 02 '20 at 21:01
  • 2
    People should know what they are disabling when calling `--no-package-lock`, don't you think? – Dimitri Kopriwa Dec 30 '20 at 22:42
  • "The --no-package-lock argument will prevent npm from creating a package-lock.json file. When running with package-lock's disabled npm will not automatically prune your node modules when installing." [Source](https://docs.npmjs.com/cli/v6/commands/npm-install) – Anas Tiour Jan 01 '21 at 14:54
  • 1
    One of the reasons for this issue is that you have package-lock.json file in your project directory. So, you may have to delete the package-lock.json file from the directory and then run the `npm install` command. Hope it will work for you. – Yisal Khan Apr 05 '21 at 05:33
  • 1
    DUDE, i could put million vote ups for this answer. You saved me a lot of time. Thanks!!! – bksi May 18 '21 at 08:35
  • 1
    Version 7.x.x of npm doesn't have the `--no-package-lock` option. – Diego Alberto Zapata Häntsch May 26 '21 at 17:59
  • Was happening to me inside docker, weird thing was that on my machine with a newer version of docker everything was building smoothly, but on the server with a slightly outdated docker the build was failing with this error. package-lock.json didn't get cached, it was pulled from the github repo. Running `npm cache clean --force` before `npm install` fixed the issue just fine :) – steak_Overcooked Nov 23 '21 at 06:21
  • We have a Gitlab CI and confirm this works. – angelokh Dec 02 '21 at 08:44
11

Our team encountered this error in our CI pipeline. However, the top answer of using --no-package-lock actually causes npm to also not use a present package-lock.json, which is definitely not the desired behavior for CI. Instead, using npm ci is now the recommended way to install in CI since it will use the existing package-lock (and nothing else).

Justin Dehorty
  • 948
  • 12
  • 23
4

Solved by running

sudo npm cache clean --force

and after that deleting package-lock.json and node_modules

and then performing

npm install 
ashad
  • 323
  • 2
  • 13