How to fix NPM maximum call stack size exceeded error

How to fix NPM maximum call stack size exceeded error for your project

Posted on July 12, 2021


Sometimes, you may see the NPM maximum call stack size exceeded error when you run the npm install command:

npm ERR! Maximum call stack size exceeded

The detail of the error may vary inside your npm-debug.log file, but this error is commonly caused by NPM unable to complete a process related to your npm install command.

For example, if you’re updating a package version, then NPM may not be able to delete the old files inside your node_modules folder and replace it with the new ones.

The exact cause of the error may vary depending on what packages you are installing, but you can use the following steps to try and fix the error:

Installing the latest NodeJS and NPM version

First, make sure that you are using the latest NodeJS and NPM versions for your project.

Now the npm install command sometimes builds native addons for NodeJS which compiles a native program written in C or C++ and uses it as a part of your Node package.

When you update your NodeJS and NPM to the latest version, the compiled native addons inside your node_modules/ folder must be rebuild using the latest NPM version for it to work.

If you don’t want to run npm install every time you change the NodeJS version, then I recommend you to use Node Version Manager to install multiple NodeJS versions on your local computer.

Once you installed the latest NodeJS and NPM software, then delete your node_modules folder and package-lock.json file:

rm -rf node_modules && rm package-lock.json

Once both are removed, then clean your NPM cache using the following command:

npm cache clean --force

Finally, try installing your dependencies again:

npm install

You should be able to install all dependencies without the maximum call stack size exceeded error now.

Related articles:

Level up your programming skills

I'm sending out an email once every Wednesday with the latest programming tutorials. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.