Rails - 找不到 JavaScript 运行时?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7092107/
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
Rails - Could not find a JavaScript runtime?
提问by Michael Durrant
I created a new Rails project using rails 3.1.0.rc4
on my local machine but when I try to start the server I get:
Could not find a JavaScript runtime. See herefor a list of available runtimes. (ExecJS::RuntimeUnavailable
)
我在rails 3.1.0.rc4
本地机器上创建了一个新的 Rails 项目,但是当我尝试启动服务器时,我得到:找不到 JavaScript 运行时。有关可用运行时的列表,请参见此处。( ExecJS::RuntimeUnavailable
)
Note: This is not about Heroku.
注意:这与 Heroku 无关。
回答by theTuxRacer
Installing a javascript runtime library such as nodejs solves this
安装 nodejs 等 javascript 运行时库可以解决这个问题
To install nodejs on ubuntu, you can type the following command in the terminal:
要在 ubuntu 上安装 nodejs,您可以在终端中键入以下命令:
sudo apt-get install nodejs
To install nodejs on systems using yum, type the following in the terminal:
要使用 yum 在系统上安装 nodejs,请在终端中键入以下内容:
yum -y install nodejs
回答by Gazler
Note from Michael 12/28/2011 - I have changed my accept from this (rubytheracer) to above (nodejs) as therubyracer has code size issues. Heroku now strongly discourage it. It will 'work' but may have size/performance issues.
Michael 2011 年 12 月 28 日的说明 - 我已将我的接受从这个(rubytheracer)更改为上面(nodejs),因为 therubyracer 有代码大小问题。Heroku 现在强烈反对它。它会“工作”,但可能有大小/性能问题。
If you add a runtime, such as therubyracer to your Gemfile and run bundle then try and start the server it should work.
如果您将运行时(例如 therubyracer)添加到 Gemfile 并运行 bundle,然后尝试启动它应该可以工作的服务器。
gem 'therubyracer'
A javascript runtime is required for compiling coffeescript and also for uglifier.
编译coffeescript和uglifier需要javascript运行时。
Update, 12/12/2011:Some folks found issues with rubytheracer (I think it was mostly code size). They found execjs (or nodejs) worked just as well (if not better) and were much smaller.
2011 年 12 月 12日更新:有些人发现 rubytheracer 存在问题(我认为主要是代码大小)。他们发现 execjs(或 nodejs)工作得同样好(如果不是更好的话)并且体积要小得多。
n.b. Coffeescript became a standard for 3.1+
nb Coffeescript 成为 3.1+ 的标准
回答by Ramiz Raja
Add following gems in your gem file
在您的 gem 文件中添加以下 gem
gem 'therubyracer'
gem 'execjs'
and run
并运行
bundle install
OR
或者
Install Node.jsto fix it permanently for all projects.
安装 Node.js以永久修复所有项目。
回答by flyingsnow
sudo apt-get install nodejs
does not work for me. In order to get it to work, I have to do the following:
sudo apt-get install nodejs
对我不起作用。为了让它工作,我必须执行以下操作:
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
Hope this will help someone having the same problem as me.
希望这能帮助和我有同样问题的人。
回答by Yang
On the windows platform, I met that problem too The solution for me is just add
在windows平台上,我也遇到了这个问题我的解决方案就是添加
C:\Windows\System32
to the PATH
到路径
and restart the computer.
并重新启动计算机。
回答by Edub Kendo
I had this issue on a Windows machine and installing node.js was the solution that finally worked for me. This came after trying multipleother routes including trying to get 'therubyracer' working. Though the github for node.js suggests that installation on windows is still unstable, the website at http://nodejs.org/had a Windows installer which worked perfectly.
我在 Windows 机器上遇到了这个问题,安装 node.js 是最终对我有用的解决方案。这是在尝试了多种其他路线之后发生的,包括尝试让“therubyracer”工作。尽管 node.js 的 github 表明在 Windows 上的安装仍然不稳定,但http://nodejs.org/的网站有一个运行良好的 Windows 安装程序。
回答by SnirD
if you already install nodejs from source for example, and execjs isn't recognizing it you might want to try this tip: https://coderwall.com/p/hyjdlw
例如,如果您已经从源代码安装了 nodejs,并且 execjs 无法识别它,您可能想尝试这个技巧:https://coderwall.com/p/hyjdlw
回答by user3576216
回答by gnerkus
Install a Javascript runtime
安装 Javascript 运行时
The error is caused by the absence of a Javascript runtime on your local machine. To resolve this, you'll need to install NodeJS.
该错误是由本地计算机上缺少 Javascript 运行时引起的。要解决此问题,您需要安装 NodeJS。
You can install NodeJS through the Node Version Manager or nvm:
您可以通过 Node Version Manager 或nvm安装NodeJS:
First, install nvm
:
首先,安装nvm
:
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash
Install Node through nvm
:
通过nvm
以下方式安装节点:
nvm install 5.9.1
This will install version 5.9.1
of Node.
这将安装 Node.js 版本5.9.1
。
回答by Patrick
I ran into this issue using Phusion Passenger (running as an nginx module) on a Redhat server. We already had a Javascript runtime installed. Other Rails apps in the same parent directory worked fine.
我在 Redhat 服务器上使用 Phusion Passenger(作为 nginx 模块运行)遇到了这个问题。我们已经安装了 Javascript 运行时。同一父目录中的其他 Rails 应用程序运行良好。
It turned out that we had a permissions issue. Run "ls -l" and see if the folder has the same owner and group as other working apps on the system. I had to run chown and chgrp on the folder (with the recursive switch) to fix it.
结果是我们遇到了权限问题。运行“ls -l”并查看该文件夹是否与系统上的其他工作应用程序具有相同的所有者和组。我不得不在文件夹上运行 chown 和 chgrp (使用递归开关)来修复它。