耙子中止!找不到JavaScript运行时

3

我是一个Ruby初学者,在开始学习的时候遇到了一些困难。

我创建了一个演示项目:

C:\Sites>rails new demo
      create
      create  README.rdoc
      create  Rakefile
      create  config.ru
      create  .gitignore
      create  Gemfile
      create  app
      create  app/assets/javascripts/application.js
      ...
      create  vendor/assets/stylesheets/.keep
         run  bundle install
Fetching gem metadata from https://rubygems.org/..........
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
Using mail (2.5.4)
Installing actionmailer (4.0.2)
...
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed

下一步,选择文件夹:
C:\Sites>cd demo

我使用了rake...然后完成了!


C:\Sites\demo>rake about
rake aborted!
Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.
C:/Sites/demo/config/application.rb:7:in `<top (required)>'
C:/Sites/demo/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)

我尝试运行服务器……但是不起作用

C:\Sites\gui>rails server
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/execjs-2.0.2/lib/execjs/run
times.rb:51:in `autodetect': Could not find a JavaScript runtime. See https://gi
thub.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUn
available)
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/execjs-2.0.2/l
ib/execjs.rb:5:in `<module:ExecJS>'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/execjs-2.0.2/l
ib/execjs.rb:4:in `<top (required)>'

请帮帮我。

2个回答

17

问题很明显,它表明没有可用的JS运行时。您可以通过将rubyracer gem添加到rails应用程序中来明确添加该依赖项,这样就应该包括JS运行时。

因此,请将gem 'therubyracer'添加到Gemfile中,然后再次运行bundle命令。然后,您可以像所需的那样运行rakerails命令 :)

如果这解决不了您的问题,请在系统上安装node.js,这应该可以确定解决您的问题。您可以使用:

sudo apt-get install nodejs # on ubuntu
brew install node # on mac-osx, if you have `homebrew` installed.

0
你需要一个 JavaScript 运行环境。
从这里 http://nodejs.org/ 安装 node.js。确保可执行文件已添加到 PATH。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接