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

Task not found in Rails 7 app #294

Closed
mdesantis opened this issue Dec 18, 2021 · 9 comments
Closed

Task not found in Rails 7 app #294

mdesantis opened this issue Dec 18, 2021 · 9 comments

Comments

@mdesantis
Copy link

mdesantis commented Dec 18, 2021

I'm trying to use js-routes in a Rails 7 app, but bundle exec rake js:routes task isn't found:

> bundle exec rake js:routes
rake aborted!
Don't know how to build task 'js:routes' (See the list of available tasks with `rake --tasks`)
ruby/3.0.3/bin/bundle:23:in `load'
ruby/3.0.3/bin/bundle:23:in `<main>'

It works correctly if the task file is copied from the library to lib/tasks application directory.

@Marcellllll
Copy link

Hi, I am having exactly the same issue. My JS cannot find js-routes anymore, and the task has disappeared as well, it looks like the gem is somehow not included in a path or something ?

Did you manage to find a solution for this ?

@mdesantis
Copy link
Author

mdesantis commented Feb 7, 2022

Did you manage to find a solution for this ?

I copied the task file from the library to lib/tasks application directory and I'm still using this workaround

@Marcellllll
Copy link

Wow, ok. Thanks for the quick reply ;-)

@Marcellllll
Copy link

Looks like it is something in Rails 7 which is breaking things. With Rails 6 sprockets can find my js-routes, with rails 7 it can no longer find it.

@bogdan
Copy link
Collaborator

bogdan commented Feb 7, 2022

I've generated a new rails 7.0 app. Run bundle add js-routes and rake js:routes and it worked fine for me.
Can you try that locally yourself?

In case you are upgrading from rails 6, is there anything in the upgrade guide related to rake tasks?

@wtfspm
Copy link
Contributor

wtfspm commented Feb 27, 2022

In my app (Rails 7, no Sprockets), it was enough to move the Sprockets conditional from lib/js_routes.rb to lib/js_routes/engine.rb so the engine is still defined and Rails can pick up the tasks.

# lib/js_routes.rb

if defined?(::Rails)                 ## move this: defined?(::Sprockets::Railtie)
  require 'js_routes/engine'
end
# lib/js_routes/engine.rb

class Engine < ::Rails::Engine
  if defined?(::Sprockets::Railtie)  ## to here
    require 'sprockets/version'
    ...

@bogdan
Copy link
Collaborator

bogdan commented Mar 3, 2022

@wtfspm It is hard to believe that fresh rails app doesn't have that issue. The root cause is till unknown. But I am open to accept a PR with such a change.

@wtfspm
Copy link
Contributor

wtfspm commented Mar 3, 2022

Yeah, it's hard to know what everyone's setup is. When you said you generated a new Rails 7 app, I assumed you included Sprockets since it's the default, and with Sprockets defined, the engine is loaded, so no issue. Happy to submit a PR, though I'm curious if this fixes the issue for @mdesantis or @Marcellllll

@bogdan
Copy link
Collaborator

bogdan commented Mar 7, 2022

When you said you generated a new Rails 7 app, I assumed you included Sprockets since it's the default, and with Sprockets defined, the engine is loaded, so no issue

Hm, you are right. It was a surprise for me that sprockets-rails is included in Gemfile even in Rails 7.x.

Merged your PR and released js-routes 2.2.3.

@bogdan bogdan closed this as completed Mar 7, 2022
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

No branches or pull requests

4 participants