Error: spawnSync ENOENT when using rails option
DE-ZIX opened this issue · 5 comments
I just installed this pack on my application and tried it using the 'rails' option in the configs. When running jest, it gives me the following error:
$ jest
FAIL tests/unit/example.spec.js
● Test suite failed to run
Error compiling 'index.js.erb', status: 'null', signal: 'null', error: Error: spawnSync bin/rails ENOENT!
at erbTransformer (node_modules/jest-erb-transformer/index.js:102:13)
at processFile (node_modules/jest-erb-transformer/index.js:110:33)
at Object.process (node_modules/jest-erb-transformer/index.js:121:12)
at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:453:35)
at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:523:40)
at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 1.247`
Running without the rails option also gives an error, pretty much the same error, it just changes a bit:
$ jest
RUNS tests/unit/example.spec.js
Traceback (most recent call last):
3: from /node_modules/jest-erb-transformer/erb_transformer.rb:11:in `<main>'
2: from C:/Ruby26-x64/lib/ruby/2.6.0/erb.rb:901:in `result'
FAIL tests/unit/example.spec.js/ruby/2.6.0/erb.rb:901:in `eval'
● Test suite failed to run
Error compiling 'index.js.erb', status: '1', signal: 'null', error: undefined!
at erbTransformer (node_modules/jest-erb-transformer/index.js:103:13)
at processFile (node_modules/jest-erb-transformer/index.js:111:33)
at Object.process (node_modules/jest-erb-transformer/index.js:122:12)
at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:453:35)
at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:523:40)
at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 1.362s
I've debugged all the way to the index.js of this package only so far. All the configs are passing and no problem is being reported regarding the userConfigs according to the code.
My platform is Windows 10: 10.0.19041.685.
I am using Ruby 2.6.5 and Rails 5.2.4.4.
I've seen other people having the same error with the 'bin/rails' runner in other packages, they've reported that in windows, changing the runner would solve their problems: https://stackoverflow.com/questions/48703240/module-build-failed-error-spawn-bin-rails-enoent
My .erb loader in webpacker looks like this:
...
options:
{
runner: '${/^win/.test(process.platform) ? 'ruby ' : ''}bin/rails runner',
}
...
Indeed, it does have a verification if it is running in windows platform and changes the values accordingly.
However, I forced the code to have the following values:
ruby bin/rails
ruby bin\\rails
bin\\rails
bin\\rails runner
ruby bin\\rails runner
All with and without the runner in the config.args.runner
having the 'runner'
value and none have worked. I don't know why it is not finding the rails bin. Or if not finding the rails bin is the correct thing I should investigate.
I have not tested in other platforms yet. If help is needed to solve this issue I am more than glad to help, I just opened the issue because I have no lead to where should I be looking to solve this issue.
Hi @DE-ZIX,
Thanks for letting me know about this. I've only developed and used the module on linux/mac machines, so didn't encounter this error myself.
I will spin up a windows machine and see if I can replicate the error you're getting. Hopefully, should be a quick fix of adding the windows specific args and conditional, mentioned in the stack overflow you linked to. I'll let you know how it goes.
@DE-ZIX I got the same errors as you when I ran it on a windows setup.
I've added in the windows specific args based on that process.platform
test you mentioned, and it now works on my windows machine.
I've released it in v1.2.0 on npm. Update to that version and let me know how it goes.
https://github.com/cpcwood/jest-erb-transformer/releases/tag/1.2.0
Thanks, Chris
Hi @cpcwood thank you very much for taking the time and fixing it! I tested it here and now it works perfectly! Just one small problem happened. I've seen you added this piece of code:
if (child.status !== 0 || !!child.stderr.toString()) {
if (child.error && child.error.code === 'ETIMEDOUT') {
throw new Error(`Compilation of '${filePath}' timed out after ${config.timeout}ms!`)
} else {
throw new Error(`Error compiling '${filePath}', status: '${child.status}', signal: '${child.signal}', error: ${child.stderr.toString()}!`)
}
}
The condition in the if
before was:
if (child.status !== 0) {
In my ruby console, I constantly get a warning about hiredis. This is something I should look into in my repo, but I've never had the time to investigate it:
WARNING: could not load hiredis extension, using (slower) pure Ruby implementation.
But this warning is harmless, all it says is that the code is going to run slower. So much that this warning happens everytime I run something from rails and everything runs fine.
However, the code was considering this an error, since (I don't know why) it was giving a value to child.stderr
, so it would not go foward with compilation.
I managed to dodge this by removing || !!child.stderr.toString()
, but I don't think that is a correct thing to do. I don't know if it might open space for errors to go through, but at the same time warnings shouldn't stop the code from running.
@DE-ZIX yeah looks like you are right. I might have been being over-cautious throwing errors on any stderr. As I didn't have any warnings I didn't catch this issue.
I've removed it and checked it through with the tests, and all is still working as expected.
Will release a new version for you :)