ExecJS and could not find a JavaScript runtime

2019-01-01 06:01发布

I'm trying to use the Mongoid / Devise Rails 3.1 template (Mongoid and Devise), and I keep getting an error stating ExecJS cannot find a JavaScript runtime. Fair enough when I didn't have any installed, but I've tried installing Node.js, Mustang and the Ruby Racer, but nothing is working.

I could not find a JavaScript runtime. See sstephenson/ExecJS (GitHub) for a list of available runtimes (ExecJS::RuntimeUnavailable).

What do I need to do to get this working?

14条回答
倾城一夜雪
2楼-- · 2019-01-01 06:33

Just add ExecJS and the Ruby Racer in your gem file and run bundle install after.

gem 'execjs'

gem 'therubyracer'

Everything should be fine after.

查看更多
柔情千种
3楼-- · 2019-01-01 06:35

For amazon linux(AMI):

sudo yum install nodejs npm --enablerepo=epel
查看更多
不再属于我。
4楼-- · 2019-01-01 06:36

Don't Use RubyRacer as it is bad on memory. Installing Node.js as suggested by some people here is a better idea.

This list of available runtimes that can be used by ExecJs Library also documents the use of Node.js

https://github.com/sstephenson/execjs

So, Node.js is not an overkill, and much better solution than using the RubyRacer.

查看更多
一个人的天荒地老
5楼-- · 2019-01-01 06:39

I had a similar problem: my Rails 3.1 app worked fine on Windows but got the same error as the OP when running on Linux. The fix that worked for me on both platforms was to add the following to my Gemfile:

gem 'therubyracer', :platforms => :ruby

The trick is knowing that :platforms => :ruby actually means only use this gem with "C Ruby (MRI) or Rubinius, but NOT Windows."

Other possible values for :platforms are described in the bundler man page.

FYI: Windows has a builtin JavaScript engine which execjs can locate. On Linux there is not a builtin although there are several available that one can install. therubyracer is one of them. Others are listed in the execjs README.md.

查看更多
有味是清欢
6楼-- · 2019-01-01 06:41

Adding the following gem to my Gemfile solved the issue:

gem 'therubyracer'

Then bundle your new dependencies:

$ bundle install
查看更多
无与为乐者.
7楼-- · 2019-01-01 06:41

Add following gems in your gem file

gem 'therubyracer'
gem 'execjs'

and run

bundle install

you are done :)

查看更多
登录 后发表回答