Webpack callback being called more than once
Closed this issue · 4 comments
It seems like the case: Module build failed: Error: rails-erb-loader failed with code: -2
triggers the callback twice. This leads to the very unhelpful error message:
../loader-runner/lib/LoaderRunner.js:106
throw new Error("callback(): The callback was already called.");
^
Error: callback(): The callback was already called.
at context.callback (../node_modules/loader-runner/lib/LoaderRunner.js:106:10)
at ChildProcess. (../node_modules/rails-erb-loader/index.js:125:7)
at ChildProcess.emit (events.js:188:13)
at maybeClose (internal/child_process.js:978:16)
at Socket.stream.socket.on (internal/child_process.js:395:11)
at Socket.emit (events.js:188:13)
at Pipe._handle.close (net.js:610:12)
This error hides the actual relevant error message that is causing this issue that is emitted here: https://github.com/usabilityhub/rails-erb-loader/blob/master/index.js#L129
The other place the callback is being triggered is in the else
clause here: https://github.com/usabilityhub/rails-erb-loader/blob/master/index.js#L125
Hey @josephfarina. Thanks for the report. I had trouble finding information on the constraints and guarantees of the child process callbacks and seem to have made an assumption here that was wrong.
I think it might be appropriate to use a flag to ensure that the callback is only called once.
Were you able to determine what was causing the error itself?
Yes, I think a flag would solve this issue fine.
The error I've been getting is either the one below or a -2
code that resulted from setting the option.runner
as RAILS_ENV=... bin/rails runner
due to the parsing of the runner string.
Module build failed: Error: rails-erb-loader failed with code: 1
at ChildProcess. (/.../node_modules/rails-erb-loader/index.js:125:16)
at ChildProcess.emit (events.js:188:13)
at maybeClose (internal/child_process.js:978:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:265:5)
@ ./...js 2:0-40
@ ./...js
@ ./...js
The command '/bin/sh -c rails assets:precompile' returned a non-zero code: 1
Ah, cheers @josephfarina. FYI you should use the env
option to set the RAILS_ENV
. Happy to take a PR for the immediate fix for this bug if you're willing. Otherwise I'll try to make some time when I return to work next week.
Awesome thanks for the help!
Here is a PR: https://github.com/usabilityhub/rails-erb-loader/pull/76/files
Let me know if it is okay!