Docker Community Forums

Share and learn in the Docker community.

Npm ERR! Maximum call stack size exceeded

I’m using Ubuntu 20.04 running on WSL 2 Windows 10 Home build 2004 x64

Docker 19.03.13

I’m trying to run a hello world node application and when I try to install the dependencies (express) I get this:

[3/3] RUN npm install:
#7 7.285 npm notice
#7 7.285 npm notice New patch version of npm available! 7.0.8 -> 7.0.9
#7 7.286 npm notice Changelog:
#7 7.286 npm notice Run npm install -g npm@7.0.9 to update!
#7 7.286 npm notice
#7 7.299 npm ERR! Maximum call stack size exceeded
#7 7.432
#7 7.432 npm ERR! A complete log of this run can be found in:
#7 7.433 npm ERR! /root/.npm/_logs/2020-11-10T18_46_56_236Z-debug.log
failed to solve with frontend dockerfile.v0: failed to build LLB: executor failed running [/bin/sh -c npm install]: runc did not terminate sucessfully

Here’s is my Dockerfile

FROM node

COPY ./ ./

RUN npm install

CMD ["npm", "start"]

This error is almost always means you have a problem with recursion in JavaScript code, as there isn’t any other way in JavaScript to consume lots of stack. Sometimes calling a recursive function over and over again, causes the browser to send you Maximum call stack size exceeded error message as the memory that can be allocated for your use is not unlimited.

How to fix it?

Wrap your recursive function call into a -

  • setTimeout
  • setImmediate
  • process.nextTick

Also, you can localize the issue by setting a breakpoint on RangeError type of exception , and then adjust the code appropriately.