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

ActionController::RoutingError (No route matches [GET] "/packs/js/application-56a22cf11b022415f36b.js") #2688

Closed
RomanKrasavtsev opened this issue Aug 8, 2020 · 14 comments

Comments

@RomanKrasavtsev
Copy link

According to the readme, in development, webpacker should compile assets on demand, but if I don't run bin/webpack-dev-server I have the error message ActionController::RoutingError (No route matches [GET] "/packs/js/application-56a22cf11b022415f36b.js").

$ rails --version
Rails 6.0.3.2

$ rails new heroku
...
✨  Done in 7.08s.
Webpacker successfully installed 🎉 🍰

$ ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin19]

$ yarn --version
1.22.4

$ node --version
v13.13.0

$ rails g controller welcome
...

$ vim config/routes.rb

Rails.application.routes.draw do
  # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html

  root 'welcome#index'
end

$ yarn add tailwindcss
...

$ vim app/javascript/packs/application.js
...
import "tailwindcss/base";
import "tailwindcss/components";
import "tailwindcss/utilities";
...

$ vim postcss.config.js
...
    require('tailwindcss'),
    require('autoprefixer'),
...

$ vim app/views/welcome/index.html.erb
<div class="bg-blue-100 border-t border-b border-blue-500 text-blue-700 px-4 py-3" role="alert">
  <p class="font-bold">Informational message</p>
  <p class="text-sm">Some additional text to explain said message.</p>
</div>
    
$ rails s
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
=> Booting Puma
=> Rails 6.0.3.2 application starting in development
=> Run `rails server --help` for more startup options
Puma starting in single mode...
* Version 4.3.5 (ruby 2.7.0-p0), codename: Mysterious Traveller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://127.0.0.1:3000
* Listening on tcp://[::1]:3000
Use Ctrl-C to stop
Started GET "/" for ::1 at 2020-08-08 16:11:51 +0200
   (1.0ms)  SELECT sqlite_version(*)
Processing by WelcomeController#index as HTML
  Rendering welcome/index.html.erb within layouts/application
  Rendered welcome/index.html.erb within layouts/application (Duration: 1.1ms | Allocations: 191)
/Users/romankrasavtsev/.rvm/gems/ruby-2.7.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/helper.rb:355: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/Users/romankrasavtsev/.rvm/gems/ruby-2.7.0/gems/sprockets-4.0.2/lib/sprockets/base.rb:118: warning: The called method `[]' is defined here
[Webpacker] Everything's up-to-date. Nothing to do
Completed 200 OK in 23ms (Views: 17.8ms | ActiveRecord: 0.0ms | Allocations: 7569)


Started GET "/packs/js/application-56a22cf11b022415f36b.js" for ::1 at 2020-08-08 16:11:51 +0200

ActionController::RoutingError (No route matches [GET] "/packs/js/application-56a22cf11b022415f36b.js"):

actionpack (6.0.3.2) lib/action_dispatch/middleware/debug_exceptions.rb:36:in `call'
web-console (4.0.4) lib/web_console/middleware.rb:132:in `call_app'
web-console (4.0.4) lib/web_console/middleware.rb:28:in `block in call'
web-console (4.0.4) lib/web_console/middleware.rb:17:in `catch'
web-console (4.0.4) lib/web_console/middleware.rb:17:in `call'
actionpack (6.0.3.2) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (6.0.3.2) lib/rails/rack/logger.rb:37:in `call_app'
railties (6.0.3.2) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (6.0.3.2) lib/active_support/tagged_logging.rb:80:in `block in tagged'
activesupport (6.0.3.2) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (6.0.3.2) lib/active_support/tagged_logging.rb:80:in `tagged'
railties (6.0.3.2) lib/rails/rack/logger.rb:26:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (6.0.3.2) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (6.0.3.2) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.2.3) lib/rack/method_override.rb:24:in `call'
rack (2.2.3) lib/rack/runtime.rb:22:in `call'
activesupport (6.0.3.2) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (6.0.3.2) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.3.2) lib/action_dispatch/middleware/static.rb:126:in `call'
rack (2.2.3) lib/rack/sendfile.rb:110:in `call'
actionpack (6.0.3.2) lib/action_dispatch/middleware/host_authorization.rb:82:in `call'
webpacker (4.2.2) lib/webpacker/dev_server_proxy.rb:23:in `perform_request'
rack-proxy (0.6.5) lib/rack/proxy.rb:57:in `call'
railties (6.0.3.2) lib/rails/engine.rb:527:in `call'
puma (4.3.5) lib/puma/configuration.rb:228:in `call'
puma (4.3.5) lib/puma/server.rb:713:in `handle_request'
puma (4.3.5) lib/puma/server.rb:472:in `process_client'
puma (4.3.5) lib/puma/server.rb:328:in `block in run'
puma (4.3.5) lib/puma/thread_pool.rb:134:in `block in spawn_thread'

But there is no issue if I runbin/webpack-dev-server:

$ bin/webpack-dev-server
ℹ 「wds」: Project is running at http://localhost:3035/
ℹ 「wds」: webpack output is served from /packs/
ℹ 「wds」: Content not from webpack is served from /Users/romankrasavtsev/Downloads/Linguatheka/heroku/public/packs
ℹ 「wds」: 404s will fallback to /index.html
ℹ 「wdm」: Hash: adadf7c4e654143b8cd7
Version: webpack 4.44.1
Time: 4736ms
Built at: 08/08/2020 4:15:21 PM
                                     Asset       Size       Chunks                         Chunk Names
    js/application-56a22cf11b022415f36b.js   2.52 MiB  application  [emitted] [immutable]  application
js/application-56a22cf11b022415f36b.js.map   2.69 MiB  application  [emitted] [dev]        application
                             manifest.json  364 bytes               [emitted]
ℹ 「wdm」: Compiled successfully.
$ rails s
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
=> Booting Puma
=> Rails 6.0.3.2 application starting in development
=> Run `rails server --help` for more startup options
Puma starting in single mode...
* Version 4.3.5 (ruby 2.7.0-p0), codename: Mysterious Traveller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://127.0.0.1:3000
* Listening on tcp://[::1]:3000
Use Ctrl-C to stop
Started GET "/" for ::1 at 2020-08-08 16:16:10 +0200
   (0.9ms)  SELECT sqlite_version(*)
Processing by WelcomeController#index as HTML
  Rendering welcome/index.html.erb within layouts/application
  Rendered welcome/index.html.erb within layouts/application (Duration: 0.9ms | Allocations: 191)
/Users/romankrasavtsev/.rvm/gems/ruby-2.7.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/helper.rb:355: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/Users/romankrasavtsev/.rvm/gems/ruby-2.7.0/gems/sprockets-4.0.2/lib/sprockets/base.rb:118: warning: The called method `[]' is defined here
Completed 200 OK in 17ms (Views: 12.0ms | ActiveRecord: 0.0ms | Allocations: 6478)

What did I miss? Thanks.

@rickiesmooth
Copy link

I'm seeing the same issue

@guillaumebriday
Copy link
Member

Please check in your webpacker.yml file that the compile option is set to true: https://github.com/rails/webpacker/blob/master/lib/install/config/webpacker.yml#L52

@rickiesmooth
Copy link

@guillaumebriday the issue occurs with my production build, should i set it to true there too?

@guillaumebriday
Copy link
Member

If you want the compilation on demand yes.

The production build is not compile on demand. You need to precompile it with:

# compiles in production mode by default unless NODE_ENV is specified
bundle exec rails webpacker:compile

@rickiesmooth
Copy link

I see, I don't want to compile on demand, but the assets used to get compiled when I did: bundle exec rails webpacker:compile which doesn't seem to work anymore since the build fails when I upgrade from 5.1.1 → 5.2.1

@guillaumebriday
Copy link
Member

Can you put your logs here when you run the command?

@rickiesmooth
Copy link

It looks like a one off issue, in a past dependabot update the build failed with:

     Failure/Error: raise ActionController::RoutingError, "No route matches [#{env['REQUEST_METHOD']}] #{env['PATH_INFO'].inspect}"
     ActionController::RoutingError:
       No route matches [GET] "/transfer_window/email-verification-lock.svg"

but in a new dependabot PR the build went fine 🤷

@guillaumebriday
Copy link
Member

Hum ok.

Feel free to close the issue then 👍

@ndrean
Copy link

ndrean commented Nov 18, 2020

I upgraded the gem to 5.2.1 and ran bundle exec rails webpacker:install, but I can't run rails without running bin/webpack-dev-server, it doesn't find the js files.
When running webpacker:install, I have:
bundle exec rails webpacker:install
identical config/webpacker.yml
Copying webpack core config
exist config/webpack
identical config/webpack/development.js
identical config/webpack/environment.js
identical config/webpack/production.js
identical config/webpack/test.js
Copying postcss.config.js to app root directory
identical postcss.config.js
Copying babel.config.js to app root directory
identical babel.config.js
Copying .browserslistrc to app root directory
identical .browserslistrc
The JavaScript app source directory already exists
apply /Users/utilisateur/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/webpacker-5.2.1/lib/install/binstubs.rb
Copying binstubs
exist bin
identical bin/webpack
identical bin/webpack-dev-server
File unchanged! The supplied flag value not found! .gitignore
Installing all JavaScript dependencies [5.2.1]
run yarn add @rails/webpacker@5.2.1 from "."

@jaredlt
Copy link

jaredlt commented Mar 2, 2021

Running ./bin/webpack before running rails server seems to have fixed this for me. I only had to run this once and now it compiles during runtime as normal (ie. I don't need to run it every time before calling rails s).

My situation: Rails was compiling on development great. I watched a video that said you could also run bin/webpack-dev-server in a sperate terminal for js hot reloading. Tried this and all was fine. Closed everything down and later tried to just rails s and received the same error as OP. Closing down rails, running ./bin/webpack once seems to have fixed something. Now I can just run rails s and it will compile on load 🤷

@nishajgd
Copy link

nishajgd commented Jan 25, 2022

For me the issue was when the node version had upgraded. The application version and the system version was different. When I upgraded my system one to match the application it started working. As it does not show any visible node version mismatch errors, I am pointing that here. Hoping this might help someone. Thanks

@therealrodk
Copy link

Running ./bin/webpack before running rails server seems to have fixed this for me.

This worked for me, as well. Thanks to @jaredlt!

@manojongraph
Copy link

Running ./bin/webpack before running rails server seems to have fixed this for me. I only had to run this once and now it compiles during runtime as normal (ie. I don't need to run it every time before calling rails s).

My situation: Rails was compiling on development great. I watched a video that said you could also run bin/webpack-dev-server in a sperate terminal for js hot reloading. Tried this and all was fine. Closed everything down and later tried to just rails s and received the same error as OP. Closing down rails, running ./bin/webpack once seems to have fixed something. Now I can just run rails s and it will compile on load 🤷

This Work for me Thanks

@p-schlickmann
Copy link

if nothing else worked for you, make sure you have this in your production.rb file:

config.public_file_server.enabled = true
config.assets.compile = false

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

10 participants