Skip to content
This repository

ExecJS::RuntimeError on new Windows apps (gibberish produced) #48

Closed
karpah opened this Issue September 20, 2011 · 24 comments

12 participants

Rebecca Skinner Joshua Peek Emile Silvis Sam Ruby Brian Hogan / New Auburn Personal Computer Services Toshinori Kajihara Mads Mobæk schiffmand BricePuls John Pray Puyttre Brice
Rebecca Skinner

Note: this isn't an issue I'm having, and I'm not entirely sure it's a ExecJS issue, but I've seen it come up three times today for Windows folks starting new apps and getting quite baffled, and I'd like to be able to help them fix it!

The error looks like so for a new app (this user was following the RailsTutorial)
https://gist.github.com/1228994

And the user's setup/Gemfile.lock is like so:
https://gist.github.com/1229054

I thought this may have been tied to the issue fixed in execjs 1.2.7 but apparently not. :(

Emile Silvis

Thanks for taking the time to help :)

Joshua Peek
Collaborator

Theres no ExecJS backtrace in that gist.

Sam Ruby

Related discussion, including a backtrace: http://forums.pragprog.com/forums/148/topics/9665#posts-26286

Joshua Peek
Collaborator

Still need more info, but heres some things to try:

  1. Use sstephenson/execjs not kennyj/execjs
  2. Try version 1.2.7
  3. Try version 1.2.4. This was before some windows related changes were introduced.
  4. See if you can find out your cscript version cscript //? (also what windows version)
  5. Do you have node.js installed?
Brian Hogan / New Auburn Personal Computer Services

1.2.4 works. 1.2.7 does not.

I encounter this on Windows 7 / CScript v5.8

Forcing 1.2.4 in the gemfile fixes the error.

edit: no NodeJS installed. Clean machine

Joshua Peek
Collaborator

@napcs interesting. Do you think you could binary search test between 1.2.4 and 1.2.7. Would like to find the regressing commit.

Brian Hogan / New Auburn Personal Computer Services

@josh I can certainly give it my best shot. Already narrowed this down to something between 1.2.6 and 1.2.7, as 1.2.5 and 1.2.6 gems both work fine.

Joshua Peek
Collaborator

Could it be this 53c5f05 commit?

Brian Hogan / New Auburn Personal Computer Services

That's the only difference you did other than the node UTF one. Also these problems didn't start till yesterday. What's the escaping for? I didn't see a unit test for the output that gave me an indication of what the escaping was supposed to look like.

Joshua Peek
Collaborator

Ah crap, I bet the escaping is screwing up the command args "cscript //E:jscript //Nologo //U".

Maybe try removing the escaping from this line output = sh("#{Shellwords.join([@binary, filename])} 2>&1").

We just need to support the case where the binary or filename would have spaces in it.

Brian Hogan / New Auburn Personal Computer Services

Yes. Shellwords isn't the best approach as it has interesting side effects:

Shellwords.escape binary
=> "c:\\\\program\\ files" 

Definitely not what you're looking for.

 binary = 'c:/program files'
 Shellwords.escape binary
 => "c:/program\\ files" 

From the docs, Shellwords "Escapes a string so that it can be safely used in a Bourne shell command line."

That's not gonna be a good fit for Windows. When I've done this for Windows, I've simply wrapped the thing with double quotes. The problem here is that you need a solution that's generic.

What do you suggest?

Toshinori Kajihara

I tested shellwords in windows a little.

I think that shellwords does not performed well in windows.
@josh 's comment is right. But, if filename(or cscript path) include a space , "&" and so on, it will not perform well.

ex.

C:\Sites>dir
...
2011/09/21 01:10 19 a&b.coffee
2011/09/21 01:10 19 a b.coffee
...

C:\Sites>irb
irb(main):001:0> require 'shellwords'
=> true
irb(main):002:0> IO.popen(Shellwords.join(['c:\windows\node.exe', 'a&b.coffee']))
=> #
irb(main):003:0>
node.js:203
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module 'C:\Sites\a&b.coffee'
at Function._resolveFilename (module.js:318:11)
at Function._load (module.js:263:25)
at Array. (module.js:454:10)
at EventEmitter._tickCallback (node.js:195:26)

irb(main):004:0* Shellwords.join(['c:\windows\node.exe', 'a&b.coffee'])
=> "c:\\windows\\node.exe a\&b.coffee"

irb(main):005:0* IO.popen(Shellwords.join(['c:\windows\node.exe', 'a b.coffee']))
=> #
irb(main):006:0>
node.js:203
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module 'C:\Sites\a'
at Function._resolveFilename (module.js:318:11)
at Function._load (module.js:263:25)
at Array. (module.js:454:10)
at EventEmitter._tickCallback (node.js:195:26)

irb(main):007:0* Shellwords.join(['c:\windows\node.exe', 'a b.coffee'])
=> "c:\\windows\\node.exe a\ b.coffee"

can't find a\&b.coffee and a\ b.coffee

Sam Ruby

Confirmed, commit 53c5f05 fails for me, and commit 642067e works for me.

Also reverting just the following one line resolves this issue for me: 53c5f05#L0L123

Joshua Peek
Collaborator

I think I'd like to keep the shellwords stuff around for unix but we'll need an alternative method for windows.

Thinking this api:

if ExecJS.windows?
  def shell_escape(*args)
    # ???
  end
else
  def shell_escape(*args)
    Shellwords.join(args)
  end
end

Any ideas?

Joshua Peek
Collaborator

Haven't tested on windows, but maybe this will work 1332be0?

Mads Mobæk

I just debugged the same problem and can confirm that 1.2.4 works while 1.2.7 don't. This wasn't on my machine, but I managed to get a screenshot comparing 1.2.4 and 1.2.7.

As far I can tell the difference lies in encoding?

Sam Ruby

@josh: with 1332be0 I can't even find a JS runtime. There are two problems here, @binary has spaces and is meant to be multiple shell tokens, and the escape character on Windows is a caret not a backslash. See #49 for my attempt to fix both. Tested on Windows 7.

Joshua Peek
Collaborator

Pulled in Sam's patch. Please test and I'll ship a new ExecJS release.

Thanks for the help guys.

schiffmand

I have same problem. I just tested with execjs 1.2.4 on Windows XP and it works.

Thanks

Joshua Peek
Collaborator

1.2.8 is out

Joshua Peek josh closed this September 20, 2011
BricePuls

I'm receiving the same error while running the Ruby on Rails tutorial with execjs 1.4.0. Reverting to 1.2.4 resolves the issue.

John Pray

+1. Same experience as BricePuls, on Windows 7 64-bit.

Puyttre

I managed to fix this from using Win8 64-bit with the help of BricePuls and josh. If you're still having problems after you've tried everything else, try this:

  1. Run gem install --version '1.2.4' execjs
  2. Add gem 'execjs', '1.2.4' anywhere in your Gemfile.
  3. Run bundle install
  4. Start your server with rails s and your problem should be solved.
Brice

I followed Puyttre's directions and the exact problem posed on this thread was fixed! Thanks so much!!

I'm running Win8 64-bit too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.