rake db:create - 找不到 JavaScript 运行时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9057475/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 08:31:55  来源:igfitidea点击:

rake db:create - Could not find a JavaScript runtime

javascriptruby-on-railsrubyrake

提问by Only Bolivian Here

Here is the error I get:

这是我得到的错误:

sergio@sergio-VirtualBox:~/blog$ rake db:create
rake aborted!
Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.

(See full trace by running task with --trace)

sergio@sergio-VirtualBox:~/blog$ 

So after some searching it seems I need to install a Javascript runtime for Ruby.

因此,经过一番搜索后,我似乎需要为 Ruby 安装一个 Javascript 运行时。

Is there a difference between the many different options? It seems Node.js is the easiest to install, will this come back to bite me or is this choice OK?

许多不同的选项之间有区别吗?似乎 Node.js 是最容易安装的,这会回来咬我还是这个选择可以?

This answer, seems to be what I'm looking for but I don't know how to make use of it. Where do I find this "gemfile" and is it a per rails project file or a global ruby file? I'm very confused and can't seem to get my bearings and multiple answers contradict each other and don't solve the issue.

这个答案,似乎是我正在寻找的,但我不知道如何利用它。我在哪里可以找到这个“gemfile”,它是每个 rails 项目文件还是全局 ruby​​ 文件?我很困惑,似乎无法理解我的方向,多个答案相互矛盾,无法解决问题。

Add this to your Gemfile

gem 'therubyracer', require: "v8"

and run

bundle install

将此添加到您的 Gemfile

gem 'therubyracer',需要:“v8”

并运行

捆绑安装

回答by djlumley

Ruby itself doesn't require a JS runtime, but a default new Rails application does.

Ruby 本身不需要 JS 运行时,但默认的新 Rails 应用程序需要。

There's a file called Gemfilein your main application directory (i.e. per Rails project) which is a list of gems required for your project that you can install using bundle install.

Gemfile在您的主应用程序目录(即每个 Rails 项目)中有一个文件,它是您的项目所需的 gem 列表,您可以使用bundle install.

Adding the line gem 'therubyracer'and then bundle installwill install the ruby racer JS runtime, which I've found to be the simplest if you're on a 64bit OS.

添加该行gem 'therubyracer',然后bundle install将安装 ruby​​ Racer JS 运行时,如果您使用的是 64 位操作系统,我发现这是最简单的。

You can find more information about your Gemfileat the Bundlersite.

您可以GemfileBundler网站上找到有关您的更多信息。

回答by Ben Zhang

Have you installed Node.js on your computer yet? It needs to be installed on your computer as well.

你有没有在你的电脑上安装 Node.js?它也需要安装在您的计算机上。

here is the link to download, http://nodejs.org/#download

这是下载链接,http://nodejs.org/#download

回答by Michael Durrant

There are several fairly similar options such rubytheracer, node and execjs.

有几个相当相似的选项,例如 ruby​​theracer、node 和 execjs。

rubytheracer has fallen out of favor due to its code size. Vendors such as Heroku (for rails) actively discourage it.

rubytheracer 由于其代码大小而失宠。Heroku(用于 Rails)等供应商积极阻止它。

I currently recommend node.js

我目前推荐 node.js

More info at Rails - Could not find a JavaScript runtime?

Rails 上的更多信息- 找不到 JavaScript 运行时?

回答by FahadJ

I had the same error, but then I reinstalled Ruby193 with all the checkboxes (Tc/Tk, associate rb, and add to PATH).

我有同样的错误,但后来我用所有复选框(Tc/Tk,关联 rb,并添加到 PATH)重新安装了 Ruby193。

And then deleted the GEMFile.lock

然后删了 GEMFile.lock

Edited the Gemfile whereever I saw gem therubyracer, I changed it to: gem therubyracer, :platform => :ruby

在我看到 gem therubyracer 的任何地方编辑 Gemfile,我将其更改为:gem therubyracer, :platform => :ruby

  • Then bundle install

  • Then rake db:drop

  • Then rake db:create

  • Then rake db:migrate

  • 然后 bundle install

  • 然后 rake db:drop

  • 然后 rake db:create

  • 然后 rake db:migrate

and so on

等等

回答by Buminda

insert gem 'therubyracer' in Gemfile in a new line 1. run

在 Gemfile 中的新行中插入 gem 'therubyracer' 1. 运行

gem install therubyracer -v '0.11.4'

gem install therubyracer -v '0.11.4'

  1. run

bundle install

捆绑安装

This will work

这将工作

回答by Aeon

Just gem install "therubyracer"and it just works.

只是gem install "therubyracer",它只是有效。