Error (stdout maxBuffer exceeded) after removing unrelated gem
Closed this issue · 4 comments
I'm getting an error that seems to make sense...sounds like the erb code is returning something too large for the buffer. What's weird is that it only appeared after removing a seemingly unrelated gem.
ERROR in ./app/javascript/lib/i18n-data.js.erb
Module build failed: Error: stdout maxBuffer exceeded
// i18n-data.js.erb
<% I18n.backend.send(:init_translations) unless I18n.backend.initialized? %>
export default <%= I18n.backend.send(:translations).to_json.html_safe %>;
I only started getting the error when I remove the npm-rails gem from my Gemfile. I had already removed all the other npm-rails related code and have been using Rails webpacker successfully.
It seems that somehow npm-rails in the Gemfile prevents the maxBuffer error. Further research showed npm-rails has a railtie, but nothing there seems like it should affect rails-erb-loader. The gem also doesn't have any dependencies besides Rails, is the only thing changing in my Gemfile.lock
Upon further review, it seems that by removing npm-rails, the locales returned in the locale file change from using I18n.available_locales
to including all of them which would certainly be buffer breaking
That's actually still an issue, was reported against webpacker as well rails/webpacker#554 as well but I think it needs to be fixed here.
@pawelniewie I saw that one before creating mine. The error message is definitely the same, but I think the context is different. Not being able to render that large of a string might just be a limitation. I'd be interested to know if other erb
loaders run into similar problems (like .html.erb
or .js.erb
through sprockets) but a good solution might just be to reconsider what you're importing
Hey guys, so sorry to have not responded. This is absolutely something that can go wrong with the current implementation.
See execFile
documentation. If your file size exceeds maxBuffer
then yes, you will hit this exception.
There are two ways this can be fixed:
- Add a
maxBuffer
option torails-erb-loader
so that consumers can configure it to their requirements. This is the easiest solution and I will happily take a PR for this. - Replace use of
execFile
withchild_process.spawn
, which is streaming and therefore will never hit the buffer limit. This is the preferred solution, but I didn't implement it myself because it wasn't yet needed.
I won't be able to address this issue myself any time soon, but will review and merge PRs if you want to provide one.