I want to limit the memory usage of node on production - ideally using --max_old_space_size.
I've read that in heroku node(v8) has a limit of 1.5 GB before it starts garbage collection. The current setup only has the server with 2.5 GB, and around 1.5 of that is already taken up by non-webpacker Rails.
I've looked at this issue: #1189 which tries to only set the development webpacker instance.
Can I just adapt this script for production like this?
package.json
{
"scripts": {
"webpacker": "node --max_old_space_size=460 node_modules/.bin/webpack --config config/webpack/production.js"
}
}
@stom01 thanks, i've been looking for this. though, it still didn't fix it for me on Heroku. any ideas?
It's a rails app using webpacker with reactJS
just not sure if i'm setting this in the wrong place
Set an environment variable with the value you want
NODE_OPTIONS=--max-old-space-size=4096
Then run webpack normally. Node will pickup the options from there.
I've found an easier way.
Open bin/webpack and edit the bottom code like this.
APP_ROOT = File.expand_path("..", __dir__)
Dir.chdir(APP_ROOT) do
ARGV << '--max-old-space-size=500' if ENV["RAILS_ENV"] == 'production'
Webpacker::WebpackRunner.run(ARGV)
end
Here is the default content of bin/webpack .
https://github.com/rails/webpacker/blob/master/lib/install/bin/webpack
Probably related https://github.com/rails/webpacker/issues/2143
Running with @seuros suggestion worked for me
Set an environment variable with the value you want
NODE_OPTIONS=--max-old-space-size=4096Then run webpack normally. Node will pickup the options from there.
Most helpful comment
Set an environment variable with the value you want
Then run webpack normally. Node will pickup the options from there.