rails / cssbundling-rails

Bundle and process CSS in Rails with Tailwind, PostCSS, and Sass via Node.js.
MIT License
579 stars 83 forks source link

Fix Rake CSS Build task error with Yarn binary not being found #43

Closed bkuhlmann closed 2 years ago

bkuhlmann commented 2 years ago

Overview

I'm afraid the 0.2.5 patch introduced a bug with asset compilation both for local development and when deploying to Heroku in which the yarn binary can no longer be found.

Steps to Recreate

To recreate, run rails css:build locally and you'll now see the following output in your console:

/Users/bkuhlmann/.cache/frum/versions/3.0.2/bin/ruby: No such file or directory -- /Users/bkuhlmann/Engineering/Companies/demo/bin/yarn (LoadError)
/Users/bkuhlmann/.cache/frum/versions/3.0.2/bin/ruby: No such file or directory -- /Users/bkuhlmann/Engineering/Companies/demo/bin/yarn (LoadError)
yarn run v1.22.17
$ sass ./app/assets/stylesheets/application.sass.scss ./app/assets/stylesheets/application.css --no-source-map --load-path=node_modules
✨  Done in 0.56s.

While the above isn't a catastrophic failure locally, it does crash Heroku deployments (might affect other server too). Here's an example where you can see the above failure but via my CLI when talking to a Heroku Stage server:

iTerm2-84zdHHjW

Desired Behavior

I don't know if a revert of the above patch is necessary but maybe we need to split compilation between a development and production environment for deployment purposes? Either that or fix the root problem where Rake can't detect the yarn binary?

Environment

liangmicha commented 2 years ago

In the meantime, here's a workaround that we've been using within our own codebase to avoid downgrading the gem:

# lib/tasks/css_build_workaround.rake
namespace :css do
  desc "Workaround for css:build"
  task :build_workaround do
    system("yarn install")
  end
end

Rake::Task["css:build"].enhance ["css:build_workaround"]
dhh commented 2 years ago

So this is fixed on rails/main via https://github.com/rails/rails/pull/43641. But yeah, need to come up with a solution where we're not running yarn install twice on Rails 6.1.4 but also dealing with the fact that bin/yarn might not be there. cc @zarqman

dhh commented 2 years ago

Reverted via https://github.com/rails/cssbundling-rails/commit/b1a456287d3df1560947c8bbb0858518ae51dad8 for now.

I think the correct solution for double yarn install is to zero out yarn:install for Rails 6.1.x (it's already not used with rails/main).