Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
516 views
in Technique[技术] by (71.8m points)

ruby - Rails 6.1.1 doesn't load the webpacker created CSS files in production mode

this is my first time asking a question here, I hope I would explain my problem well. In one of my recent tasks, I'm upgrading our app to Ruby and Rails (Ruby 2.6.6 > 2.7.2, Rails 6.0.3.2. > 6.1.1) I had several issues along the way, upgraded some gems and JS libraries. The application runs fine in development mode. However when I switch to production mode, I run these commands to compile and run the server.

RAILS_ENV=production bundle exec rake webpacker:compile
./node_modules/webpack/bin/webpack.js --config webpack.config.js

When I run the app, in production mode it looks running normal, but when I go to localhost:3000 it throws several 500 errors regarding to CSS files. I see the main page of the app as plain HTML, without CSS.

2021-01-22 11:50:51 -0500 Rack app ("GET /assets/stylesheets/app-styles-3661efb317da3fb28f52.css" - (127.0.0.1)): #<NoMethodError: undefined method `match?' for #<ActionDispatch::FileHandler:0x00007ff610502c20>>
2021-01-22 11:50:25 -0500 Rack app ("GET /assets/landing.debug-05588bd014e46c264aaf6e00d2f5c570dd7ca3ed42336c2ff6d5c05bf986afe2.js" - (127.0.0.1)): #<NoMethodError: undefined method `match?' for #<ActionDispatch::FileHandler:0x00007ff610502c20>>
2021-01-22 11:50:25 -0500 Rack app ("GET /assets/companyLogo-6700adf796812269b9428251803c253b9c073095ef511d3619d269a0fdd96435.png" - (127.0.0.1)): #<NoMethodError: undefined method `match?' for #<ActionDispatch::FileHandler:0x00007ff610502c20>>

Files which are mentioned in the error are exists under the /public folder. In the browser's page source, I can see the path as well. When I click the folder path on page source, I see this error on the browser. An unhandled lowlevel error occurred. The application logs may have details.

When I check the docs of RoR, the match? method for ActionDispatch::FileHandler is not there, but in 6.0.3.2 docs, it is deprecated without a notice, maybe.?. It is not something I call intentionally, it is probably called somewhere in Rails when the app is running on production mode.

I have those helper in my erb files.

<%= javascript_pack_tag 'application' %>
<%= stylesheet_pack_tag 'application' %>

I tried replacing them with

<%= stylesheet_pack_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>

but no luck :(

I tried this as well.

Is anyone have an idea how can I make sure Rails is loading these files and accessible in the user side? Or any better debugging suggestions are appreciated! Thanks in advance!

Note: When I switch to development mode, everything works fine. BTW, Some Packages I use:

"@rails/webpacker": "5.2.1" #-> was 4.0.2
"webpack-bundle-analyzer": "3.3.2"
"webpack-manifest-plugin": "3.0.0-rc.0" #-> was 2.0.4
"webpack-cli": "4.4.0", #-> was 3.3.0 and it was only devDependency
question from:https://stackoverflow.com/questions/65850244/rails-6-1-1-doesnt-load-the-webpacker-created-css-files-in-production-mode

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

We had the same issue with the match? method missing for ActionDispatch::FileHandler

We traced it back to: https://github.com/romanbsd/heroku-deflater/issues/54

Removing the heroku-deflater gem fixed it for us


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...