Webpacker: In Production running node with flag --max_old_space_size

Created on 27 Mar 2019  路  5Comments  路  Source: rails/webpacker

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"
  }
}

Most helpful comment

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.

All 5 comments

@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

Running with @seuros suggestion worked for me

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ijdickinson picture ijdickinson  路  3Comments

ytbryan picture ytbryan  路  3Comments

suhomlineugene picture suhomlineugene  路  3Comments

ankitrg picture ankitrg  路  3Comments

itay-grudev picture itay-grudev  路  3Comments