npm ERR! code ELIFECYCLE
Tags: node, javascript
Published: 2021-11-25 14:03:19

Article originally published here : [https://bootiful.org/blog/npm-err-code-elifecycle](https://bootiful.org/blog/npm-err-code-elifecycle)


The goal of this article is to help you to debug the annoying "npm ERR! code ELIFECYCLE". You don't have time to know why this happens, and you want to correct it now ? That is the right place to do so.

## Some context

Node.js allows developers to use JavaScript to create new command line tools. NPM is a package manager for Node.js. It's the default one. It consists of a command line client, and an online database of public and private packages, called the "npm registry", and is available [here](https://www.npmjs.com/).

When you create an application developed on the Node.js platform, you can set up an error management system to take care of the problems encountered. The "ELIFECYCLE" error occurs when an unknown error causes the application to fail. Probably another software was running and conflicted with yours. When not, you have the possibility to redo a clean installation of your application.

## npm ERR! code ELIFECYCLE

<figure class="figure">![showing error](https://res.cloudinary.com/bdavidxyz-com/image/upload/e_shadow:25,r_40/v1637592412/bootstrap/npmerr.png)

<figcaption class="figure-caption">An annoying bug, indeed.</figcaption>

</figure>

The "ELIFECYCLE" error corresponds neither to a syntax error in the code nor to a permission problem because other sentences are then used to notify the error. This error reported that an unknown event caused the application to run normally. So you can check that another application is not using a resource that you need. This can be for example a port of the machine, or a component. You need to examine the log and see when the app has a problem.

## How to debug

**1 - clear the npm cache** The problem could also be with the installation of your application which encountered an unknown problem. To solve this, it is possible to start again on a healthy basis by reinstalling all the modules used by the application, and by emptying the NPM node package manager cache. The "npm cache clean" command clears the npm cache. Add the "--force" argument to force the operation.

    npm cache clean --force

**2 - delete node_modules** just go to the root directory of your application and delete the "node_modules" folder. To remove the directory from the command line, the command depends on your operating system. The "rm" command is used with a Unix operating system. The arguments "r" and "f" indicate respectively to delete the subfolders and to force the deletion without asking for confirmation.

With Linux-based system:

    rm -rf node_modules

With Windows-based system :

    rd /s /q "node_modules"

**3 - reinstall node_modules** The "npm install" wil trigger a full download and installation of modules you need in your application. All you have to do then is to use the command "npm start" (check your package.json accordingly) to restart your application

With npm:

    npm install

With yarn:

    yarn

## A word of caution

With Unix, you use the "rm" command to remove files. It's a too simple command; you just type rm followed by a list of files. The main problem is : "rm" is too simple. It's far too easy to remove more than you initially wanted, and once something is gone, it is gone forever. There are some hacks that make rm somehow more safe. To understand why it's impossible to reclaim deleted files, you need to know a bit about how the Unix filesystem works.

## Credits

*   [https://stackoverflow.com/a/49505612/2595513](https://stackoverflow.com/a/49505612/2595513)
*   [https://docstore.mik.ua/orelly/unix3/upt/ch14_03.htm](https://docstore.mik.ua/orelly/unix3/upt/ch14_03.htm)
*   [https://www.journaldunet.fr/web-tech/developpement/1441095-comment-corriger-l-erreur-npm-elifecycle-sous-node-js/](https://www.journaldunet.fr/web-tech/developpement/1441095-comment-corriger-l-erreur-npm-elifecycle-sous-node-js/)