在heroku上部署Rails应用程序时,出现以下错误,
remote: Bundle completed (163.81s) remote: Cleaning up the bundler cache. remote: -----> Installing node-v8.10.0-linux-x64 remote: -----> Detecting rake tasks remote: -----> Preparing app for Rails asset pipeline remote: Running: rake assets:precompile remote: Yarn executable was not detected in the system. remote: Download Yarn at https://yarnpkg.com/en/docs/install remote: rake aborted! remote: Uglifier::Error: Unexpected token punc «;», expected punc «,» remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/uglifier-4.1.20/lib/uglifier.rb:234:in `parse_result' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/uglifier-4.1.20/lib/uglifier.rb:216:in `run_uglifyjs' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/uglifier-4.1.20/lib/uglifier.rb:168:in `compile' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/compressing.rb:65:in `block in js_compressor=' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/legacy_proc_processor.rb:31:in `call' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:75:in `call_processor' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:57:in `block in call_processors' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in `reverse_each' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in `call_processors' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:134:in `load_from_unloaded' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:60:in `blockin load' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:44:in `load' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:20:in `block in initialize' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:47:in `load' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/base.rb:66:in `find_asset' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/base.rb:73:in `find_all_linked_assets' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:142:in `block in find' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:114:in `block (2 levels) in logical_paths' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:228:in `block in stat_tree' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:212:in `block in stat_directory' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:209:in `each' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:209:in `stat_directory' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:227:in `stat_tree' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:105:in `each' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:105:in `block in logical_paths' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:104:in `each' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:104:in `logical_paths' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:140:in `find' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:186:in `compile' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:68:in `block (3 levels) in define' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.2/lib/rake/sprocketstask.rb:147:in `with_logger' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:67:in `block (2 levels) in define' remote: /tmp/build_eb48b48285b82dae89f9dfd764c51c22/vendor/bundle/ruby/2.4.0/gems/rake-12.3.2/exe/rake:27:in `' remote: Tasks: TOP => assets:precompile remote: (See full trace by running task with --trace) remote: remote: ! remote: ! Precompiling assets failed. remote: ! remote: ! Push rejected, failed to compile Ruby app. remote: remote: ! Push failed remote: Verifying deploy...
我已经将production.rb
中的行修改为
config.assets.js_compressor = Uglifier.new(harmony: true)
但错误仍然存在。
答案 0 :(得分:0)
似乎出现了问题,因为您的Sprockets或Rails版本无法与较新的Uglifier很好地配合使用。至少在Rails 3.2.22中,会生成.map
文件,然后将其视为下一个后缀。例如。链轮试图将application.js.map
压缩为js文件。
一种解决方案是通过在您的config/environments/production.rb
文件(或您喜欢的任何配置文件)中添加一行来告诉Sprockets忽略地图文件:
config.assets.precompile[0] = Proc.new { |path| !File.extname(path).in?(['.js', '.css', '.map']) }
在复制粘贴上面的代码之前,您应验证要替换先前存在的config.assets.precompile
数组中的正确项目。该数组包含确定哪些文件被处理的过程。对我来说,数组中有两个项目,第一个如下:
#<Proc:0x0055819620f6f8@/home/me/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-3.2.22/lib/rails/application/configuration.rb:48>
查看上述proc的定义的指示位置(gems/railties-3.2.22/lib/rails/application/configuration.rb:48
)会显示:
Proc.new{ |path| !File.extname(path).in?(['.js', '.css']) }
...选择每个非js,非css文件。将'.map'
添加到该排除列表中将防止.map
文件通过压缩器被馈入。