Error handling can either be something that's incredibly aggravating, or satisfying as a developer. Errors inevitably happen, but sometimes even after falling down a google rabbit hole that leads to questions on Stackoverflow, to github threads, can often lead to even more aggravation and not an actual solution. Especially when there is no forward momentum in the errors. At least when an error changes to something new, you know you've done something right. Maybe.
I'm going to try and walk through a solution to the Rails 6 Webpacker::Manifest::MissingEntryError, in the hope that one person stumbles across this in the future and it helps.
After setting up a new project in Rails, when attempting to fire up the development server, I was automatically hit with this error:
Webpacker can't find application.js in /Users/danischuhman/Development/code/photo_app/public/packs/manifest.json. Possible causes:
1. You want to set webpacker.yml value of compile to true for your environment
unless you are using the `webpack -w` or the webpack-dev-server.
2. webpack has not yet re-run to reflect updates.
3. You have misconfigured Webpacker's config/webpacker.yml file.
4. Your webpack configuration is not creating a manifest.
Your manifest contains:
What the error means is that Webpacker can't find the application, and is failing at square one to compile. None of the files that are needed in order for Webpacker to run properly, are being generated. I don't know precisely why this happens, or where there is a failure to cause this issue, just that it happens. And it's annoying.
Some of the github threads talked about aliasing a css file, and altering the <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
tag within application.html.erb file. Other workarounds talked about removing the tag entirely. Removing the tag allows everything to run properly, except, it doesn't solve the issue and leads to further errors down the road, which really isn't the best way to handle debugging. Others had solutions that worked for some people, but did not for me.
The solution, which I only came to after discussing it with a good friend, and much more experienced engineer, is pretty straightforward.
First thing, is to run rails webpacker:install
and overwrite the existing webpacker.yml file.
Next is to delete the node_modules folder in your repo, and if it exists, the public/packs folder. In my case, my public/packs folder wasn't even being generated, so there was nothing to delete there.
Then run yarn install
, bundle
, and then rails webpacker:install
, overwriting any files it suggests you to overwrite.
Hopefully, if everything has then been installed properly, when you fire up rails s
your application should open to the main page, and there should no longer be an error. Which, I hope if you've found this blog post, is precisely what's happened for you.
In the future, when building my next Rails App, I will follow this order of operations, just to make sure everything is generated properly and to hopefully avoid the error:
bundle install
rails db:migrate
rails webpacker:install
yarn install
rails server
For the time being, I'm glad to have found a solution that works, and hopefully know in the future how to work around it, should the problem arise again.
Here are some links to discussion of this particular issue, to see just some of the solutions offered up by other engineers.
Top comments (7)
I had the same error, while your solution didn't work for me one of my instructors sent me another fix. In bin/server
I can now get back to work!
what do you mean by bin/server?
Thanks for writing this post, it definitely helped get me back up and running. The only thing I had to do differently was change the version of node I was running from the latest to the latest stable version that node recommended for most users. Once I set my version on my machine to that, I followed these steps and it works! Just wanted to share that additional piece and say thanks for writing this post!
I'm really glad it helped! I've run into the problem a few times now, and all the scouring on the web didn't actually help. And that's so frustrating!
Downgrading the version of node to 16 solve my problem.
That might work for me as well. On localhost I have Node 16 and it works. On the server Node 18 and it doesn't. Thanks for the hint!
Not that easy to pin the Node version on an Alpine Docker Image. I guess I will just migrate from Rails 6 to Rails 7 and get rid of Webpack completely.