2

I update my rails app to pass at 5.1.X to day, but surprise, my config to minify JS and CSS dosn't work anymore...

config.assets.js_compressor = Uglifier.new(output: {comments: /^!/})

** Invoke yarn:install (first_time) ** Execute yarn:install Yarn executable was not detected in the system. Download Yarn at https://yarnpkg.com/en/docs/install ** Execute assets:precompile rake aborted! Uglifier::Error: Invalid assignment

If I comment out the line, it works, but JS is not minified and there is inaccessible on site... like all others assets, but there are present in cache in /public folder... I don't understand why asset pipeline doesn't work now?!

So how can I stay with classic asset pipeline and disabled yarn call ?

0

1 Answer 1

0

I have been looking into this and as it is a very new issue, I would think about posting also an issue on Uglifier github page. I do not understand why Uglifier is causing problem to yarn as asset pipeline files are in app while yarn will keep them in node_modules.

I believe the issue here is that Uglifier already works on production files (in fact that is a production setting) and the asset pipeline will be working with yarn. You can require files in your application.js and .scss from the yarn node_modules folder, they will be included in your assets.

in this guide you can find out how rails requires the different components

  active_record/railtie
  action_controller/railtie
  action_view/railtie
  action_mailer/railtie
  active_job/railtie
  action_cable/engine
  rails/test_unit/railtie
  sprockets/railtie

I gave a very quick look at this, could not find anything relevant to yarn in railties/lib/rails/all.rb so I decided to search the rails repository for yarn keyword and find out this file

# Be sure to restart your server when you modify this file.

# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = '1.0'

# Add additional assets to the asset load path.
# Rails.application.config.assets.paths << Emoji.images_path
<%- unless options[:skip_yarn] -%>
# Add Yarn node_modules folder to the asset load path.
Rails.application.config.assets.paths << Rails.root.join('node_modules')
<%- end -%>

# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in the app/assets
# folder are already added.
# Rails.application.config.assets.precompile += %w( admin.js admin.css )

so maybe you should search for this option\[:skip_yarn\]? I wish you good luck

Fabrizio

1
  • 1
    in fact, when I comment the line (about Uglifier) in config, precompile works, assets are generated in /public folder, but there are all inaccessible on site... I don't understand why asset pipeline doesn't works now?! I don't have yarn installed, so I search solution without use it... :skip_yarn option seem to be used for no include node_module, but I don't have this on my app.
    – Matrix
    Mar 13, 2018 at 0:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.