-
Notifications
You must be signed in to change notification settings - Fork 4
Webpack required Components file not found first boot #5
Comments
The default configuration of Webpacker is to generate digests on all the packed files and store the mapping in {
"client_and_server.js": "/packs/client_and_server-bbc5157a54ad4b47beb9.js"
} I don't know the internals of the include mechanism / Sprockets but it seems it's not looking via the manifest so can't find the file as it has a digest. Rails # config/initializers/hyperloop.rb
Hyperloop.configuration do |config|
# ...
config.import(
Webpacker.manifest.lookup("client_and_server.js")&.split("/")&.last
)
end Which works provided the packs folder is added to the asset pipeline as above: # config/initializers/assets.rb
Rails.application.config.assets.paths << Rails.root.join('public', 'packs') It's a little messy but does work. Another work around is to prevent generation of the digest by changing the webpack defaults. But I assume this is a bad idea as it will probably cause caching issues, but I'm not sure: // config/webpack/custom.js
module.exports = {
externals: {
"react": "React",
"react-dom": "ReactDOM"
},
output: {
filename: 'client_and_server.js' // this prevents digest
}
}; So hyperloop-config could be changed to automatically look via the manifest.json. But this may not be possible as you can't know what is an asset or what is a webpack thing, maybe an additional explicit option And/or the Webpack example could be updated to mention the above workaround[s]. |
I also believe that adding |
So I am not sure what the conclusion of this will be but it should be either fixed, or at least documented/clarified with 0.15 release |
|
Yep, now working without that adding packs to assets hack line. |
Following Hyperloop Webpack Tutorial doesn't quite work first boot.
Declare your React library in app/javascript/packs/client_and_server.js:
Run the command webpack, so it will generate the package client_and_server.js into public/packs
Tell Hyperloop where is located your package:
In order to help Rails and Hyperloop to find the client_and_server.js package:
But there is some kind of bug. I did the above, cleared cache and started the server but it refused to boot: couldn't find file 'client_and_server' with type 'application/javascript' (Sprockets::FileNotFound). However I can see the ./public/packs folder in the lookup paths in the error output below, so the config is correct.
I got it to work by commenting out `config.import 'client_and_server' and booting the server once. Of course Hyperloop can't find the component but at least the app boots this time.
Then I stop the server, add the config.import line back and restart the server. This time it can find the file and boots and the component works in Hyperloop.
So, what is Rails doing on that first boot that bin/webpack didn't do? Our webpacker config is stock but I note yours is different, perhaps Rails changed something.
I just reproduced the issue in our app by
rm -rf tmp/cache
again. You don't even have to load the app in a browser, just booting the app is enough.Error Output
Other issues with the docs:
webpack
(noob info I know but important)require()
and I get errors to that effect?The text was updated successfully, but these errors were encountered: