9

I am using https://github.com/srs/gradle-node-plugin to launch NPM tasks as part of my build.

But, webpack is now running out of heap space, reporting FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

I can't figure out any way to tell the the NpmTask to pass the --max-old-space-size flag directly to node (placing it anywhere in the NpmTask args property ends up passing the flag as an argument to the npm script, which ignores it or to webpack which fails because it doesn't know the arg).

I found this github issue: https://github.com/srs/gradle-node-plugin/issues/141, but it only seems to relate to the NodeTask, not NpmTask. Looking at it, I'm thinking NpmTask needs to be extended with an extra options property like NodeTask now has.

Is there a global config "node.js" way I can force node to use more heap space until I figure out how to get NpmTask to do what I want?

Shorn
  • 19,077
  • 15
  • 90
  • 168
  • I notice a few folks have upvoted this question. I never did figure out how to configure the setting in the question; but my problem was actually some bad code/webpack config (can't remember now exactly) that was causing webpack or typescript to run out of control and chew up all available heap. – Shorn Sep 09 '19 at 09:40

1 Answers1

3

Provide the NODE_OPTIONS environment variable when running Gradle:

NODE_OPTIONS="--max-old-space-size=1024" ./gradlew myNpmTask
Vic Seedoubleyew
  • 9,888
  • 6
  • 55
  • 76
  • 1
    is it possible to pass NODE_OPTIONS to Gradle without using an environment variable (e.g. in gradle.properties or build.gradle.kts)? – AlexO Mar 13 '23 at 00:05