“找不到JavaScript运行时”,我该如何安装?

3

我无法启动Rails服务器。 显然,我没有JavaScript运行时。

$ rails s
c:/Ruby22/lib/ruby/gems/2.2.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:94:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'uglifier'. (Bundler::GemRequireError)
Gem Load Error is: Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes.

我访问了以下链接:

https://github.com/rails/execjs

但是我不知道该怎么做。那么,我应该如何“安装”JavaScript运行环境呢?

另外,这是我的GemFile文件:

source 'https://rubygems.org'

git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  "https://github.com/#{repo_name}.git"
end


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platform: :mri
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
  gem 'web-console', '>= 3.3.0'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
3个回答

7

找不到JavaScript运行时

您需要安装nodejs

sudo apt-get install nodejs

或者在你的Gemfile中添加therubyracer gem。
gem 'therubyracer'

我在某处读到过,therubyracer 在 Windows 上无法工作。 - Zak Janzi
我不知道它在Windows上是否无法工作,但是知道这个信息还是很好的。 - Deepak Mahakale
你可以选择第一种选项,然后按照Windows的方式进行。 - Deepak Mahakale
但问题是,我已经安装了Node.js,但仍然收到相同的错误。可能是什么原因? - Zak Janzi
检查您是否拥有PATH - Deepak Mahakale
请您能详细阐述一下吗? - Zak Janzi

1
一些 gem 需要 JavaScript 引擎(通常只是在开发时需要)。
您可以安装 NodeJS 或 therubyracer,并在 Gemfile 中添加 gem 'therubyracer'

0

我已经尝试过了,但仍然收到相同的错误(我安装了v6.9.2)。我正在运行Rails 5.0.1和Ruby 2.2.5。 - Zak Janzi

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