攻击者:Heroku上的推送失败-Rails 5.2.3

时间:2019-06-13 10:02:30

标签: ruby-on-rails ruby heroku push uglifier

我正在尝试在Heroku上部署不带数据库的应用程序,而Uglifier出现此错误:

rake aborted!
Uglifier::Error: Unexpected token: keyword (const). To use ES6 syntax, harmony mode must be enabled with Uglifier.new(:harmony => true).

/tmp/build_03ed840249175186eece9eb6563a8337/app/assets/config/manifest.js:2

/tmp/build_03ed840249175186eece9eb6563a8337/vendor/bundle/ruby/2.5.0/gems/uglifier-4.1.20/lib/uglifier.rb:234:in `parse_result'

根据建议,我将其替换为production.rb

config.assets.js_compressor = :uglifier

使用

config.assets.js_compressor = Uglifier.new(harmony: true)

但是然后,我在推送它时遇到了这个问题:

rake aborted!
Uglifier::Error: Unexpected character '#'     

/tmp/build_c9603da773e8afa6c70b30bb536a85ab/vendor/bundle/ruby/2.5.0/gems/uglifier-4.1.20/lib/uglifier.rb:234:in `parse_result'       

/tmp/build_c9603da773e8afa6c70b30bb536a85ab/vendor/bundle/ruby/2.5.0/gems/uglifier-4.1.20/lib/uglifier.rb:216:in `run_uglifyjs' 

搜索后,建议似乎与我在production.rb中所做的完全相同...

我跑步时

RAILS_ENV=production rake assets:precompile --trace

我没有任何错误!

这是我的宝石文件:

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.5.1'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.2'
# Use pg/don't use it
#gem 'pg'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 4.1.20'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby

# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# 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', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'

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

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false

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

group :development do
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 2.15'
  gem 'selenium-webdriver'
  # Easy installation and use of chromedriver to run system tests with Chrome
  gem 'chromedriver-helper'
end

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

#Style
gem 'bootstrap', '~> 4.3.1'
gem 'jquery-rails', '~> 4.3.3', '>= 4.3.3'
gem 'font-awesome-sass', '~> 5.8.1'

更新

我从一个新应用开始,这个应用带有数据库。 逐步推送,以查看错误的确切位置。添加我的自定义CSS之后,没有任何.js,我用惯常的方法编辑了 assets.rb

Rails.application.config.assets.precompile += [/.*\.png/,/.*\.ico/,/.*\.jpg/,/.*\.js/,/.*\.scss/,/.*\.svg/]
Rails.application.config.assets.precompile << %w( *.scss *.js )
Rails.application.config.assets.paths << Rails.root.join("lib")
Rails.application.config.assets.paths << Rails.root.join("vendor")

错误来了... 也许我的 assets.rb 写得不好?

更新2

试图用 Closure-compiler 替换 Uglifier gem,出现以下错误:

rake aborted!
       Closure::Error: sh: 1: java: not found
       /tmp/build_e1adeef66970d059737b424179dfef90/app/assets/config/manifest.js:2
       /tmp/build_e1adeef66970d059737b424179dfef90/vendor/bundle/ruby/2.5.0/gems/closure-compiler-1.1.14/lib/closure/compiler.rb:68:in `compile_files'

谢谢您的回答

0 个答案:

没有答案