web-dev-qa-db-fra.com

Actifs rake: précompiler Rails_ENV = la production ne fonctionne pas correctement

J'essaie de précompiler des ressources à l'aide de la commande rake assets:precompile Rails_ENV=production, mais je reçois toujours l'erreur ci-dessous.

** Invoke assets:precompile (first_time)
    ** Execute assets:precompile
    /usr/bin/Ruby /usr/bin/rake assets:precompile:all Rails_ENV=production Rails_GROUPS=assets --trace
    ** Invoke assets:precompile:all (first_time)
    ** Execute assets:precompile:all
    ** Invoke assets:precompile:primary (first_time)
    ** Invoke assets:environment (first_time)
    ** Execute assets:environment
    ** Invoke environment (first_time)
    ** Execute environment
    ** Invoke tmp:cache:clear (first_time)
    ** Execute tmp:cache:clear
    ** Execute assets:precompile:primary
    rake aborted!
    LoadError: cannot load such file -- uglifier
      (in /home/cool_tech/cool_tech/app/assets/javascripts/application.js)
    /usr/lib/Ruby/gems/2.0.0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:251:in `require'
    /usr/lib/Ruby/gems/2.0.0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:251:in `block in require'
    /usr/lib/Ruby/gems/2.0.0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:236:in `load_dependency'
    /usr/lib/Ruby/gems/2.0.0/gems/activesupport-3.2.14/lib/active_support/dependencies.rb:251:in `require'
    /usr/lib/Ruby/gems/2.0.0/gems/actionpack-3.2.14/lib/sprockets/compressors.rb:31:in `registered_js_compressor'
    /usr/lib/Ruby/gems/2.0.0/gems/actionpack-3.2.14/lib/sprockets/bootstrap.rb:18:in `block in run'
    /usr/lib/Ruby/gems/2.0.0/gems/actionpack-3.2.14/lib/sprockets/compressors.rb:80:in `call'
    /usr/lib/Ruby/gems/2.0.0/gems/actionpack-3.2.14/lib/sprockets/compressors.rb:80:in `compressor'
    /usr/lib/Ruby/gems/2.0.0/gems/actionpack-3.2.14/lib/sprockets/compressors.rb:74:in `compress'
    /usr/lib/Ruby/gems/2.0.0/gems/sprockets-2.2.2/lib/sprockets/processing.rb:265:in `block in js_compressor='
    /usr/lib/Ruby/gems/2.0.0/gems/sprockets-2.2.2/lib/sprockets/processor.rb:29:in `call'
    /usr/lib/Ruby/gems/2.0.0/gems/sprockets-2.2.2/lib/sprockets/processor.rb:29:in `evaluate'
    /usr/lib/Ruby/gems/2.0.0/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'
    /usr/lib/Ruby/gems/2.0.0/gems/sprockets-2.2.2/lib/sprockets/context.rb:193:in `block in evaluate'
    /usr/lib/Ruby/gems/2.0.0/gems/sprockets-2.2.2/lib/sprockets/context.rb:190:in `each'
    /usr/lib/Ruby/gems/2.0.0/gems/sprockets-2.2.2/lib/sprockets/context.rb:190:in `evaluate'
    /usr/lib/Ruby/gems/2.0.0/gems/sprockets-2.2.2/lib/sprockets/bundled_asset.rb:26:in `initialize'
    /usr/lib/Ruby/gems/2.0.0/gems/sprockets-2.2.2/lib/sprockets/base.rb:252:in `new'
    /usr/lib/Ruby/gems/2.0.0/gems/sprockets-2.2.2/lib/sprockets/base.rb:252:in `build_asset'
    /usr/lib/Ruby/gems/2.0.0/gems/sprockets-2.2.2/lib/sprockets/index.rb:93:in `block in build_asset'
    /usr/lib/Ruby/gems/2.0.0/gems/sprockets-2.2.2/lib/sprockets/caching.rb:19:in `cache_asset'
    /usr/lib/Ruby/gems/2.0.0/gems/sprockets-2.2.2/lib/sprockets/index.rb:92:in `build_asset'
    /usr/lib/Ruby/gems/2.0.0/gems/sprockets-2.2.2/lib/sprockets/base.rb:169:in `find_asset'
    /usr/lib/Ruby/gems/2.0.0/gems/sprockets-2.2.2/lib/sprockets/index.rb:60:in `find_asset'
    /usr/lib/Ruby/gems/2.0.0/gems/actionpack-3.2.14/lib/sprockets/static_compiler.rb:19:in `block in compile'
    /usr/lib/Ruby/gems/2.0.0/gems/sprockets-2.2.2/lib/sprockets/base.rb:219:in `block in each_logical_path'
    /usr/lib/Ruby/gems/2.0.0/gems/sprockets-2.2.2/lib/sprockets/base.rb:206:in `block (2 levels) in each_file'
    /usr/lib/Ruby/gems/2.0.0/gems/sprockets-2.2.2/lib/sprockets/base.rb:196:in `each'
    /usr/lib/Ruby/gems/2.0.0/gems/sprockets-2.2.2/lib/sprockets/base.rb:196:in `each_entry'
    /usr/lib/Ruby/gems/2.0.0/gems/sprockets-2.2.2/lib/sprockets/base.rb:204:in `block in each_file'
    /usr/lib/Ruby/gems/2.0.0/gems/sprockets-2.2.2/lib/sprockets/base.rb:203:in `each'
    /usr/lib/Ruby/gems/2.0.0/gems/sprockets-2.2.2/lib/sprockets/base.rb:203:in `each_file'
    /usr/lib/Ruby/gems/2.0.0/gems/sprockets-2.2.2/lib/sprockets/base.rb:217:in `each_logical_path'
    /usr/lib/Ruby/gems/2.0.0/gems/actionpack-3.2.14/lib/sprockets/static_compiler.rb:18:in `compile'
    /usr/lib/Ruby/gems/2.0.0/gems/actionpack-3.2.14/lib/sprockets/assets.rake:56:in `internal_precompile'
    /usr/lib/Ruby/gems/2.0.0/gems/actionpack-3.2.14/lib/sprockets/assets.rake:70:in `block (3 levels) in <top (required)>'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:240:in `call'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:240:in `block in execute'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:235:in `each'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:235:in `execute'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
    /usr/lib/Ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:165:in `invoke'
    /usr/lib/Ruby/gems/2.0.0/gems/actionpack-3.2.14/lib/sprockets/assets.rake:60:in `block (3 levels) in <top (required)>'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:240:in `call'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:240:in `block in execute'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:235:in `each'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:235:in `execute'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
    /usr/lib/Ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:165:in `invoke'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/application.rb:150:in `invoke_task'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/application.rb:106:in `each'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/application.rb:106:in `block in top_level'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/application.rb:115:in `run_with_threads'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/application.rb:100:in `top_level'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/application.rb:78:in `block in run'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/application.rb:176:in `standard_exception_handling'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/application.rb:75:in `run'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/bin/rake:33:in `<top (required)>'
    /usr/bin/rake:23:in `load'
    /usr/bin/rake:23:in `<main>'
    Tasks: TOP => assets:precompile:primary
    rake aborted!
    Command failed with status (1): [/usr/bin/Ruby /usr/bin/rake assets:precomp...]
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/file_utils.rb:54:in `block in create_Shell_runner'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/file_utils.rb:45:in `call'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/file_utils.rb:45:in `sh'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/file_utils_ext.rb:37:in `sh'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/file_utils.rb:82:in `Ruby'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/file_utils_ext.rb:37:in `Ruby'
    /usr/lib/Ruby/gems/2.0.0/gems/actionpack-3.2.14/lib/sprockets/assets.rake:12:in `Ruby_rake_task'
    /usr/lib/Ruby/gems/2.0.0/gems/actionpack-3.2.14/lib/sprockets/assets.rake:21:in `invoke_or_reboot_rake_task'
    /usr/lib/Ruby/gems/2.0.0/gems/actionpack-3.2.14/lib/sprockets/assets.rake:29:in `block (2 levels) in <top (required)>'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:240:in `call'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:240:in `block in execute'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:235:in `each'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:235:in `execute'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
    /usr/lib/Ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/task.rb:165:in `invoke'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/application.rb:150:in `invoke_task'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/application.rb:106:in `each'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/application.rb:106:in `block in top_level'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/application.rb:115:in `run_with_threads'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/application.rb:100:in `top_level'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/application.rb:78:in `block in run'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/application.rb:176:in `standard_exception_handling'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/lib/rake/application.rb:75:in `run'
    /usr/lib/Ruby/gems/2.0.0/gems/rake-10.2.2/bin/rake:33:in `<top (required)>'
    /usr/bin/rake:23:in `load'
    /usr/bin/rake:23:in `<main>'
    Tasks: TOP => assets:precompile

Est-ce que quelqu'un a une idée de ce qui pourrait être faux? Merci.

33
Green

Remplacer

rake assets:precompile Rails_ENV=production

avec

rake assets:precompile (Rails_ENV=production bundle exec rake assets:precompile est la tâche de rake exacte)

Étant donné que la précompilation est effectuée uniquement en mode de production, il n'est pas nécessaire de spécifier explicitement l'environnement.

Mise à jour:

Essayez d’ajouter la ligne ci-dessous à votre Gemfile:

group :assets do
  gem 'therubyracer'
  gem 'sass-Rails', "  ~> 3.1.0"
  gem 'coffee-Rails', "~> 3.1.0"
  gem 'uglifier'
end

Puis lancez bundle install.

J'espère que ça va marcher :)

52

Avez-vous ajouté cette gemme à votre gemfile?

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

déplacez ce joyau hors du groupe d'actifs, puis exécutez à nouveau bundle, j'espère que cela vous aidera!

6
Rajdeep Singh

Pour expliquer le problème, votre erreur est la suivante:

LoadError: cannot load such file -- uglifier
      (in /home/cool_tech/cool_tech/app/assets/javascripts/application.js)

Cela signifie quelque part dans application.js, votre application fait référence à uglifier (probablement dans la zone manifest en haut du fichier). Pour résoudre le problème, vous devez soit supprimer la référence à uglifier, soit vous assurer que le fichier uglifier est présent dans votre application, d'où les réponses que vous avez fournies.


Fix

Si vous n'avez pas eu la chance d'ajouter la gemme à votre GemFile, une solution rapide serait de supprimer toute référence à uglifier dans votre application.js manifeste. Ceci, bien sûr, sera temporaire, mais vous permettra au moins de précompiler vos actifs

3
Richard Peck

J'ai eu ce problème aujourd'hui. J'ai corrigé le fait d'être explicite sur mon besoin

gem 'uglifier', '>= 1.0.3', require: 'uglifier'

J'avais le mien encore dans le groupe des actifs.

0
Andrew WC Brown

J'ai découvert que mon projet de sauvegarde fonctionnait bien si je précompilais sans bundle update. Peut-être que quelque chose n'allait pas avec la gemme mise à jour mais je ne sais pas quelle gemme a une erreur.

0
Green