nickjj / docker-rails-example

A production ready example Rails app that's using Docker and Docker Compose.
MIT License
974 stars 197 forks source link

JS entrypoint not executing #17

Closed danjebs closed 3 years ago

danjebs commented 3 years ago

First off - this package is perfect! After spending way too long trying to get Rails up and running with Docker, I came across this repo which has the nice bonus of having just the packages I needed included. Excited to dig in.

One issue that I have come across - I notice that the application.js pack is not running. After downloading, running docker-compose up --build and initialising the database, I can load the home page. However, no javascript is executing - verified by adding a console.log to the start of the application.js file and seeing nothing come up in the console.

I can set up a repo to reproduce, but literally the only thing I changed is to add a console.log. So either there is something really silly I am missing or there is a new bug that has been introduced.

https://www.loom.com/share/5241219529d94a26a889226f11f3cd69

nickjj commented 3 years ago

Hi,

I'm able to reproduce the same thing here using the master branch. Some type of regression may have happened after updating Webpacker to 6.

Would you mind checking out the 0.2.0 release of this repo and see if you get the same results? I won't be able to test that until later.

danjebs commented 3 years ago

I'll have to try that tomorrow, I was running into build errors caused by the mimemagic version 3.5.0 that was pulled.

danjebs commented 3 years ago

Hi @nickjj, I tried 0.2.0 (with Rails bumped to 6.1.3.1 to fix the issue with the yanked mimemagic) and I am seeing output from console.log in application.js

Seems it is an issue with 0.3.0 release.

nickjj commented 3 years ago

Ok thanks. I wonder if we can get away with using the latest master but downgrade Webpacker to the version used in 0.2.0.

nickjj commented 3 years ago

The PR linked to this issue is working with the latest master branch / release if you want to apply it manually in your project. Just waiting on a minor commit message change before merging it in.

It comes down to using the javascript_packs_with_chunks_tag tag in application.html.erb instead of javascript_pack_tag.

nickjj commented 3 years ago

Seems like there's another fix and this one makes more sense based on tracking a few PRs on Webpacker.

As of this comment, our Gemfile has gem 'webpacker', '~> 6.0.0.beta.7' but the Gemfile.lock file has a reference to https://github.com/nickjj/docker-rails-example/blob/eec7bc49517b492cec225c5f038b552a0d8ebe76/Gemfile.lock#L193

That release required using javascript_packs_with_chunks_tag, after I changed the lock file to use beta 7 everything works with javascript_pack_tag. I'm going to close the linked PR and apply this patch today. It just involves updating the lock file to reference webpacker (6.0.0.beta.7), building and you're good to go with no app changes.

Edit: I just pushed this fix to master and it's all working. Here's the commit: https://github.com/nickjj/docker-rails-example/commit/85f09b896435eea93680592e5d8b8cc34f8e993f

danjebs commented 3 years ago

Thanks for the speedy response @nickjj, much appreciated. I applied the change and the JS is loading.

nickjj commented 3 years ago

No problem, another change is you'll want to remove the ~> operator from the reference to Webpacker in the Gemfile too. The pessimistic operator will always pull pre.2 instead of beta.7. That's how we got into this trouble.

Here's the commit with the patch from yesterday: https://github.com/nickjj/docker-rails-example/commit/85f09b896435eea93680592e5d8b8cc34f8e993f