I've started a rails project using rails new
with --webpack=react
.
I generated a new controller updated my PostgreSQL password in the database.yml.
Up to this point, everything works fine. At this point all I'm trying to do is get react to render the default hello_react.jsx file that was generated as an example by rails.
When I put <%= javascript_pack_tag 'hello_react' %>
in my view and run the server I get the following error:
Webpacker::Manifest::MissingEntryError in Home#index Showing G:/../../../myGroceryList/app/views/home/index.html.erb where line #1 raised:
Webpacker can't find hello_react.js in G:/../../../myGroceryList/public/packs/manifest.json. Possible causes:
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. webpack has not yet re-run to reflect updates. You have misconfigured Webpacker's config/webpacker.yml file. Your webpack configuration is not creating a manifest. Your manifest contains: { }
I have pushed the project up to GitHub. Any thought on what is going wrong and how to fix this error?
RESOLVED: Resolution in comments
Jonny B,
I encountered the same issue. I was able to determine that I needed to add '.jsx' to my webpacker.yml
.
extensions:
- .js
+ - .jsx
- .sass
- .scss
- .css
I also found that webpacker:compile
was not being run on page refresh or when files were changed. I needed to run bundle exec rake assets:precompile
(or bundle exec rake webpacker:compile
) manually after each change to be able to reload and see the changes.
I am running the application via Apache+Mod_Passenger rather than using rails s
(I have too many apps in development at the same time to keep starting and stopping a server on the command line). It seems like this doesn't work well with Webpacker's compile-on-demand functionality. Starting a server with rails s
will allow me to hit the app on localhost:3000
, but the react app doesn't render correctly. After hitting the page via the Puma server on 3000, I can now see the compiled assets working in my Apache/Passenger instance. So, the on-demand compiling seems to only work properly when running in a server started on the command line (rails s
) ...which doesn't render correctly. :-/
The other option (better than running 2 servers) is to compile on the command line using bundle exec rake assets:precompile
or bundle exec rake webpacker:compile
whenever you make a change. Still a PITA, but at least it works ...for now. If I find a better solution, I'll update the answer.
After a lot of playing around, installing different version of NodeJS, Ruby, rbenv, nvm, etc., I was able to determine that the NODE_ENV
wasn't being set for the Apache/Passenger environment. Using Rbenv, I was able to add an .rbenv-vars
file in my app root containing:
NODE_ENV=development
RACK_ENV=development
RAILS_ENV=development
Now, Webpacker (and NodeJS) see that I am running in development rather than production, and the compile-on-demand is working.
RESOLUTION: As best I can tell this error fires when your public/packs folder is missing the Manifest file or is missing all together. What was happening in my case was Webpackers compilation step was silently failing and not creating the public/packs folder. I checked in a fix to the webpacker gem for this. You can see that fix and conversation here.
if this is the root cause then you can fix with either of these depending on how you prefer to install node packages
yarn install
or
npm install
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With