po5i
po5i

Reputation: 558

Increase node memory using npm package.json script

If you want to increase the memory limit in node, the option to be passed will be:

node --max-old-space-size=4096 yourFile.js

But in my scenario I am using yarn, my package.json looks like this:

{
  "name": "myapp",
  "productName": "myapp",
  "version": "1.0.0",
  "main": "app/main.js",
  ...
  "scripts": {
    "package-win": "npm run build && build --win --x64",
    "package-mac": "npm run build && build --mac",
    ...
  },
  ...

I execute yarn package-win on a windows machine to invoke electron-builder for my electron app built with react.js. But I get always npm ERR! code ELIFECYCLE Due to out of memory. In my mac also got the FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory Error but still got the packages generated (how? I don't know) when invoking yarn package-mac.

I search a lot on how to use the --max-old-space-size=4096 option, but I haven't found anything that works.

I tried "package-win": "node --max-old-space-size=4096 npm run build && build --win --x64", But the path have problems locating npm. Even if I use which npm, still which is not recognized.

Thanks for helping.

Upvotes: 1

Views: 9133

Answers (2)

varun verma
varun verma

Reputation: 9

You don't have to use option in package-win. The way you should use-

    "build-ts-prod": "node --max-old-space-size=1024 
    ./node_modules/typescript/bin/tsc --skipLibCheck --diagnostics",

Upvotes: 0

po5i
po5i

Reputation: 558

Answering to myself: Using this options in package-win is wrong. As package-win executes the build task, then:

"build": "npm run build-main && npm run build-renderer",
...
"build-main": "cross-env NODE_ENV=production node --max_old_space_size=6144 --optimize_for_size --stack_size=6144 --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.main.prod.js --progress --profile --colors",
"build-renderer": "cross-env NODE_ENV=production node --max_old_space_size=6144 --optimize_for_size --stack_size=6144 --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.renderer.prod.js --progress --profile --colors",

That way it works!

Upvotes: 3

Related Questions