How to fix "npm ERR! Maximum call stack size exceeded" in Google Cloud Build?

Viewed 5177

My latest Google Cloud Builds are failing with the following error:

Step 3/16 : RUN npm i
 ---> Running in 9b3b8df05c12
npm notice 
npm notice New patch version of npm available! 7.0.2 -> 7.0.3
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.0.3>
npm notice Run `npm install -g npm@7.0.3` to update!
npm notice 
npm ERR! Maximum call stack size exceeded

The last successful build was on October 17th. Since then, I have only made one commit which changed some typescript. Nothing in the dockerfile or NPM dependencies has changed.

The relevant section of the Dockerfile looks like this:

FROM node AS minifier
COPY MyProject/Client .
RUN npm i
RUN npm install -g grunt-cli rollup
RUN grunt release

It looks like the issue is specifically with the RUN npm i command. Is this a bug? Is there anything I can do to fix it? I did retry the build, but encountered the same error.

1 Answers

This is an issue caused due to the latest release of npm i.e. v7.0.3. There are multiple alternatives to this:

  • You can change the base image to node:15.0.0 or node:15.0.0-slim
  • Alternatively using yarn instead of npm can also fix this issue
  • Run npm cache clean --force before npm i in your Dockerfile

I'd recommend changing the base image.

Related