本文介绍了RoR 预编译资产在 rake 资产时失败:预编译 - 在基本为空的 application.js 上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行:

bundle exec rake assets:precompile RAILS_ENV=production --trace

** Execute assets:precompile:primary
rake aborted!
TypeError: Object doesn't support this property or method
  (in C:/Sites/MyApp/app/assets/javascripts/application.js)

这里是application.js的全部内容:

//= require jquery
//= require jquery_ujs
//= require_tree .

没有别的.

我尝试从 application.js 中删除三个 //= require 行,然后预编译运行没有问题.

I tried to remove the three //= require lines from application.js, the precompilation then runs with no problems.

推荐答案

看起来可能是 uglifier 和 Windows Script Host 的问题:

Looks like it might be a problem with uglifier and Windows Script Host:

https://github.com/rails/rails/issues/2847

确保您使用的是最新版本的 uglifier (1.0.4).如果您仍然遇到问题,我建议您尝试不同的编译器(例如 Closure 编译器)

Make sure you're using the last version of uglifier (1.0.4). If you're still having problems, I'd suggest trying a different compiler (e.g. Closure compiler)

Gemfile 中:

gem 'closure-compiler'

config/environments/production.rb

config.assets.js_compressor = :closure

或者完全禁用 JS 压缩:

alternatively disable JS compression altogether:

config.assets.compress = false

这篇关于RoR 预编译资产在 rake 资产时失败:预编译 - 在基本为空的 application.js 上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 04:32