Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Weird issue when using execjs in rails 4.0.13 in windows #190

Open
nathanvda opened this issue Apr 24, 2015 · 1 comment
Open

Weird issue when using execjs in rails 4.0.13 in windows #190

nathanvda opened this issue Apr 24, 2015 · 1 comment

Comments

@nathanvda
Copy link

I am trying to deploy on a Windows server (I know: I would rather not either), and I installed node.js which is normally my go-to solution to make everything work.

My setup: I am using ruby 2.1 (but I had the same error in 1.9.3), execjs 2.5.2 and rails 4.0.13.

When doing rake assets:precompile I get an empty error, like

ExecJS::RuntimeError:
  (in c:/Ruby21/lib/ruby/gems/2.1.0/bundler/gems/wice_grid-cb7fb4f178e9/vendor/assets/javascripts/wice_grid_processor.js.coffee)
(execjs):1
Tasks: TOP => assets:precompile�

(and normally I would presume some kind of more verbose error). So I ventured into my rails console, to do something like ExecJS.eval("'red'") for test, and start adding puts statements to see what was going on. I got the same kind of error.

After a while debugging, editing the code, restarting the console, i figured to use irb which starts quicker. And imagine my surprise that the tested line just works in irb, and not in the rails environment. From my logs I seem to be able to deduce that ExecJS::ExternalRuntime.eval is overruled in rails? Is that possible? Imho that is causing the problem with regards to the eval not working now.

In the rails console I always get an empty script, and in irb it is correctly translated to return eval("('red')").

Do you have an idea where I can look where/how the eval is overruled. I am guessing it is something platform specific.

Things I tried:

  • switch to coffee-script-source 1.8.0 because it has worked on another server for me: now it does not make a difference
  • switch to sprockets 2.11.0 (from 2.12.3)
  • switch to coffee-script 2.3.1 (from 2.4.0)

Any tips where to look would be greatly appreciated. Thanks in advance!

@nathanvda
Copy link
Author

I have rails code deployed on three windows servers, and on two it just worked when installing node, and on the third it did not.

I had another day of debugging, and I now know how to fix it, but I do not understand it.

As said before rake assets:precompile failed, and I was able to get the same error when doing ExecJS.compile("var a=1;"). It did fire up node correctly, and when I disabled the cleaning of the tempfile (containing the js source to be compiled/executed), I was able to just start node manually with the temp-file and it returned the correct (expected) output ([ok]).

I edited the exec_runtime function, to add more logging to get a clear view what is going wrong.

What I see is that the generated command line fails for some reason. The generated command-line is this:

node C:/Users/ADMINI~1/AppData/Local/Temp/2/execjs20150604-6088-1g2aekijs 2>&1 > C:/Users/ADMINI~1/AppData/Local/Temp/2/execjs20150604-6088-1yrs6arjson

which outputs (captured) :

 'node' is not recognized as an internal or external command,
 operable program or batch file.

and the output file is empty, and the $?.success? is false. I have no idea why this fails, because I can just execute the command at the command-line manually without any error. I have the faint idea this has something to do with the length of the command-line, but I am just guessing here.

So if I rewrite the exec_runtime as follows it just works:

    def exec_runtime(filename)
      command = binary.split(" ") << filename
      output = `#{shell_escape(*command)}`            
      if $?.success?
        output
      else
        raise exec_runtime_error(output)
      end
    end

This code was tested on windows 2003. If required I can test this works on windows 2008 and windows 2012R2. I am not sure this is just a local issue, as said: I have no explanation why the original code no longer works.

I would be happy to provide a PR if appreciated. Or do some further digging if anybody has some idea why it should fail. Or provide more info if required.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant