Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase NodeJS heap (--max-old-space-size) in Bitbucket Pipelines for Typescript/Webpack?

I am running into memory issues during the webpack packaging step in a serverless/TypeScript project.

I have tried:

  • 'increase-memory-limit' npm package to no avail
  • Calling the following command from an npm run script

  • Calling the following command directly through bitbucket-pipelines.yml.

    node --max-old-space-size=4096 ./node_modules/.bin/serverless deploy
    

It works fine locally with this command, but in Bitbucket pipelines I get the following output:

    Serverless: Bundling with Webpack...

    internal/child_process.js:323
        throw errnoException(err, 'spawn');
        ^
    Error: spawn ENOMEM
        at _errnoException (util.js:1022:11)
        at ChildProcess.spawn (internal/child_process.js:323:11)
        at exports.spawn (child_process.js:502:9)
        at Object.exports.fork (child_process.js:103:10)
        at fork (/opt/atlassian/pipelines/agent/build/node_modules/worker-farm/lib/fork.js:17:36)
        at Farm.startChild (/opt/atlassian/pipelines/agent/build/node_modules/worker-farm/lib/farm.js:106:16)
        at Farm.processQueue (/opt/atlassian/pipelines/agent/build/node_modules/worker-farm/lib/farm.js:279:10)
        at Farm.<anonymous> (/opt/atlassian/pipelines/agent/build/node_modules/worker-farm/lib/farm.js:97:21)
        at ontimeout (timers.js:475:11)
        at tryOnTimeout (timers.js:310:5)
        at Timer.listOnTimeout (timers.js:270:5)
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! [email protected] deploy: `node --max-old-space-size=4096 ./node_modules/.bin/serverless deploy "--stage"    "feattsify" "--region" "us-east-1"`
    npm ERR! Exit status 1
    npm ERR! 
    npm ERR! Failed at the [email protected] deploy script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
    npm ERR! A complete log of this run can be found in:
    npm ERR!     /root/.npm/_logs/2019-02-07T22_37_25_150Z-debug.log

I've done a lot of googling and searching here to try to find if Bitbucket has some kind of env. variable you can set for runtime args, etc., but can't seem to find anything that doesn't tie back into the aforementioned NPM package.

like image 268
Matt Cook Avatar asked Feb 08 '19 14:02

Matt Cook


1 Answers

I encountered a similar issue some time ago in some Jenkins build tasks. You might be able to solve it using the NODE_OPTION environment variable:

NODE_OPTIONS=--max_old_space_size=4096

From your error stacktrace, it looks like new node processes are beeing spawned. If you can set this environment variable, it will be used by node to pass arguments to any new processes, and so to the spawned processes that run out of memory here.

https://nodejs.org/dist/latest-v8.x/docs/api/cli.html#cli_node_options_options

like image 80
Rauks Avatar answered Sep 24 '22 01:09

Rauks