NPM build process is resource hungry

Your software
My Mautic version is: 5.0.1
My PHP version is: 8.1

NPM build exits with error code 137

M5 needs to build static assets with NPM. The NPM build process consumes too many resources/RAM and gets killed by the web server resulting in an error code 137.

My instance is on a shared hosting, but I can use 1.5GB of RAM

Terminal output

$ npm ci --prefer-offline --no-audit
npm WARN deprecated @npmcli/move-file@1.1.2: This functionality has been moved to @npmcli/fs
npm WARN deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN:

> mautic@0.0.0 postinstall
> node_modules/modernizr/bin/modernizr -c modernizr-config.json -d node_modules/modernizr/modernizr-mautic-dist.js & npm run build

Modernizr build saved to node_modules/modernizr/modernizr-mautic-dist.js

> mautic@0.0.0 build
> webpack --mode production  --config webpack.config.js

sh: line 1:  1563 Killed                  npm run build
npm ERR! code 137
npm ERR! path /var/www/mautic
npm ERR! command failed
npm ERR! command sh -c node_modules/modernizr/bin/modernizr -c modernizr-config.json -d node_modules/modernizr/modernizr-mautic-dist.js & npm run build

To me 1.5GB RAM seems plenty. Are there other factors at play?

Is there a way to optimize the build process?

Current workaround

My current workaround is:

  • rsync my instance on my local machine
  • run the npm build
  • sync back
cd /tmp
mkdir mtc
cd mtc
rsync -avz -e 'ssh -i ~/.ssh/id_rsa' .
npm ci --prefer-offline --no-audit
npx patch-package
rsync -avz -e 'ssh -i ~/.ssh/id_rsa' .

Just wondering:
Is this a workable workaround?
I can install Mautic on a local virtual box and then sync it into the hosting environment without NPM installed?
Or does Mautic require NPM for standard operation as well? (or only during installation?)

I’m not that deep into Mautic development, but NPM per se should not be necessary to run Mautic.

It just builds the assets.

That’s why running the build process locally and rsyncing the outcome to the server works for me.

I am currently experiencing the same issues. Same error, same resource hungry process being killed on German hoster uberspace (shared hosting).

Commenting to raise this again.