ExecJS 并且找不到 JavaScript 运行时
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6282307/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ExecJS and could not find a JavaScript runtime
提问by srboisvert
I'm trying to use the Mongoid / Devise Rails 3.1 template(Mongoidand Devise), and I keep getting an error stating ExecJScannot find a JavaScript runtime. Fair enough when I didn't have any installed, but I've tried installing Node.js, Mustangand the Ruby Racer, but nothing is working.
我正在尝试使用Mongoid / Devise Rails 3.1 模板(Mongoid和Devise),但我不断收到错误消息,指出ExecJS找不到 JavaScript 运行时。当我没有安装任何东西时就足够了,但是我已经尝试安装Node.js、Mustang和Ruby Racer,但没有任何效果。
I could not find a JavaScript runtime. See sstephenson/ExecJS(GitHub) for a list of available runtimes (ExecJS::RuntimeUnavailable
).
我找不到 JavaScript 运行时。请参阅sstephenson/ExecJS(GitHub) 以获取可用运行时的列表 ( ExecJS::RuntimeUnavailable
)。
What do I need to do to get this working?
我需要做什么才能让它发挥作用?
回答by vincent jacquel
Just add ExecJSand the Ruby Racerin your gem file and run bundle install
after.
只需在您的 gem 文件中添加ExecJS和Ruby Racer并运行bundle install
。
gem 'execjs'
gem 'therubyracer'
Everything should be fine after.
之后一切都应该好了。
回答by eldewall
Ubuntu Users
Ubuntu 用户
I'm on Ubuntu 11.04 and had similar issues. Installing Node.jsfixed it.
我在 Ubuntu 11.04 上遇到了类似的问题。安装 Node.js修复了它。
As of Ubuntu 13.04 x64 you only need to run:
从 Ubuntu 13.04 x64 开始,您只需要运行:
sudo apt-get install nodejs
This will solve the problem.
这将解决问题。
CentOS/RedHat Users
CentOS/RedHat 用户
sudo yum install nodejs
回答by manish nautiyal
In your Gem file, write
在您的 Gem 文件中,写入
gem 'execjs'
gem 'therubyracer'
and then run
然后运行
bundle install
Everything works fine for me :)
一切对我来说都很好:)
回答by jwfearn
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
:
我遇到了类似的问题:我的 Rails 3.1 应用程序在 Windows 上运行良好,但在 Linux 上运行时遇到与 OP 相同的错误。在两个平台上对我都有效的修复是将以下内容添加到我的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."
诀窍是知道这:platforms => :ruby
实际上意味着只能将这个 gem 与“C Ruby (MRI) 或 Rubinius,而不是 Windows”一起使用。
Other possible values for :platforms
are described in the bundler
man page.
对于其他可能的值:platforms
中描述的bundler
手册页。
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.
仅供参考:Windows 有一个内置的 JavaScript 引擎execjs
可以定位。在 Linux 上没有内置,尽管有几个可以安装。 therubyracer
是其中之一。其他在execjs
README.md中列出。
回答by JDutil
Adding the following gem to my Gemfile solved the issue:
将以下 gem 添加到我的 Gemfile 解决了这个问题:
gem 'therubyracer'
Then bundle your new dependencies:
然后捆绑您的新依赖项:
$ bundle install
回答by moschops
An alternative way is to just bundle without the gem group that contains the things you don't have.
另一种方法是在没有包含您没有的东西的 gem 组的情况下进行捆绑。
So do:
所以这样做:
bundle install --without assets
you don't have to modify the Gemfile at all, providing of course you are not doing asset chain stuff - which usually applies in non-development environments. Bundle will remember your '--without' setting in the .bundle/config file.
你根本不需要修改 Gemfile,当然前提是你没有做资产链的事情——这通常适用于非开发环境。Bundle 会记住您在 .bundle/config 文件中的“--without”设置。
回答by Ramiz Raja
Add following gems in your gem file
在您的 gem 文件中添加以下 gem
gem 'therubyracer'
gem 'execjs'
and run
并运行
bundle install
you are done :)
你完成了:)
回答by William Hu
For amazon linux(AMI):
对于亚马逊 linux(AMI):
sudo yum install nodejs npm --enablerepo=epel
回答by Sean
I had this same error but only on my staging server not my production environment. nodejs was already installed on both environments.
我有同样的错误,但只在我的临时服务器上而不是我的生产环境上。nodejs 已经安装在两个环境中。
By typing:
通过键入:
which node
I found out that the node command was located in: /usr/bin/node on production but: /usr/local/bin/node in staging.
我发现 node 命令位于:/usr/bin/node on production 但:/usr/local/bin/node in staging。
After creating a symlink on staging i.e. :
在登台上创建符号链接后,即:
sudo ln -s /usr/local/bin/node /usr/bin/node
the application then worked in staging.
该应用程序然后在登台工作。
No muss no fuss.
没有麻烦没有大惊小怪。
回答by Richard Zhang
I used to add the Ruby Racerto the Gem file to fix it. But hey, Node.jsworks!
我曾经将Ruby Racer添加到 Gem 文件中以修复它。但是,嘿,Node.js有效!