Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Don't know how to build task 'assets:precompile'" when used without sprockets #58

Closed
richardTowers opened this issue Dec 27, 2021 · 2 comments · Fixed by #59
Closed

Comments

@richardTowers
Copy link
Contributor

I'm seeing a problem running rake --tasks in a rails 7 project which has cssbundling-rails as a dependency but not sprockets.

% ▶ rake --tasks
rake aborted!
Don't know how to build task 'assets:precompile' (See the list of available tasks with `rake --tasks`)
/Users/richardtowers/Projects/sop_mark_two/Rakefile:6:in `<top (required)>'
(See full trace by running task with --trace)
with --trace
% ▶ rake --tasks --trace
rake aborted!
Don't know how to build task 'assets:precompile' (See the list of available tasks with `rake --tasks`)
/Users/richardtowers/.asdf/installs/ruby/3.0.1/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/task_manager.rb:59:in `[]'
/Users/richardtowers/.asdf/installs/ruby/3.0.1/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/task.rb:405:in `[]'
/Users/richardtowers/.asdf/installs/ruby/3.0.1/lib/ruby/gems/3.0.0/gems/cssbundling-rails-1.0.0/lib/tasks/cssbundling/build.rake:10:in `<main>'
/Users/richardtowers/.asdf/installs/ruby/3.0.1/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:60:in `load'
/Users/richardtowers/.asdf/installs/ruby/3.0.1/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:60:in `load'
/Users/richardtowers/.asdf/installs/ruby/3.0.1/lib/ruby/gems/3.0.0/gems/railties-7.0.0/lib/rails/engine.rb:661:in `block in run_tasks_blocks'
/Users/richardtowers/.asdf/installs/ruby/3.0.1/lib/ruby/gems/3.0.0/gems/railties-7.0.0/lib/rails/engine.rb:661:in `each'
/Users/richardtowers/.asdf/installs/ruby/3.0.1/lib/ruby/gems/3.0.0/gems/railties-7.0.0/lib/rails/engine.rb:661:in `run_tasks_blocks'
/Users/richardtowers/.asdf/installs/ruby/3.0.1/lib/ruby/gems/3.0.0/gems/railties-7.0.0/lib/rails/application.rb:501:in `block in run_tasks_blocks'
/Users/richardtowers/.asdf/installs/ruby/3.0.1/lib/ruby/gems/3.0.0/gems/railties-7.0.0/lib/rails/engine/railties.rb:15:in `each'
/Users/richardtowers/.asdf/installs/ruby/3.0.1/lib/ruby/gems/3.0.0/gems/railties-7.0.0/lib/rails/engine/railties.rb:15:in `each'
/Users/richardtowers/.asdf/installs/ruby/3.0.1/lib/ruby/gems/3.0.0/gems/railties-7.0.0/lib/rails/application.rb:501:in `run_tasks_blocks'
/Users/richardtowers/.asdf/installs/ruby/3.0.1/lib/ruby/gems/3.0.0/gems/railties-7.0.0/lib/rails/engine.rb:464:in `load_tasks'
/Users/richardtowers/Projects/sop_mark_two/Rakefile:6:in `<top (required)>'
/Users/richardtowers/.asdf/installs/ruby/3.0.1/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/rake_module.rb:29:in `load'
/Users/richardtowers/.asdf/installs/ruby/3.0.1/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/rake_module.rb:29:in `load_rakefile'
/Users/richardtowers/.asdf/installs/ruby/3.0.1/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:710:in `raw_load_rakefile'
/Users/richardtowers/.asdf/installs/ruby/3.0.1/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:104:in `block in load_rakefile'
/Users/richardtowers/.asdf/installs/ruby/3.0.1/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
/Users/richardtowers/.asdf/installs/ruby/3.0.1/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:103:in `load_rakefile'
/Users/richardtowers/.asdf/installs/ruby/3.0.1/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:82:in `block in run'
/Users/richardtowers/.asdf/installs/ruby/3.0.1/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
/Users/richardtowers/.asdf/installs/ruby/3.0.1/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:80:in `run'
/Users/richardtowers/.asdf/installs/ruby/3.0.1/lib/ruby/gems/3.0.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/Users/richardtowers/.asdf/installs/ruby/3.0.1/bin/rake:23:in `load'
/Users/richardtowers/.asdf/installs/ruby/3.0.1/bin/rake:23:in `<main>'

Note: I'm not trying to run assets:precompile - the error is thrown by rake --tasks.

The trace calls out build.rake:10 which looks like it assumes the assets:precompile task will exist.

Adding gem "sprockets-rails" to my Gemfile fixes the issue, but a749ca2 suggests that "Sprockets is not a dependency", so I think this is a bug.

I can have a go at a PR...

richardTowers added a commit to richardTowers/cssbundling-rails that referenced this issue Dec 27, 2021
a749ca2 suggests that "Sprockets is not a dependency", so we should not
assume that the assets:precompile task will be defined. If it's not
there, we should just skip enhancing it.

Fixes rails#58
@dhh
Copy link
Member

dhh commented Dec 31, 2021

May I ask how you get your assets served if not through sprockets or propshaft?

@dhh dhh closed this as completed in #59 Dec 31, 2021
dhh pushed a commit that referenced this issue Dec 31, 2021
a749ca2 suggests that "Sprockets is not a dependency", so we should not
assume that the assets:precompile task will be defined. If it's not
there, we should just skip enhancing it.

Fixes #58
@richardTowers
Copy link
Contributor Author

May I ask how you get your assets served if not through sprockets or propshaft?

I didn't actually get that far - I am planning on using sprockets (although I might have a look at propshaft now).

I stumbled across this while upgrading a rails 6 app. The process was something like:

  • Upgrade to rails 7
  • Remove sass-rails and add cssbundling-rails
  • rake --tasks
  • "Don't know how to build task 'assets:precompile'"
  • wat

Rails 7 dropped the dependency on Sprockets as well. So I accidentally removed the transient dependency on Sprockets when I upgraded rails and removed sass-rails. I wasn't actually trying to live without sprockets / propshaft.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants