hotwired/turbo-rails

Possible install instruction change needed for Webpacker 6

noelrappin opened this issue · 6 comments

I was trying to run the install instructions against the Webpacker 6 beta.

Taking my example which already worked against Webpacker 5, and upgrading Webpacker, my Turbo install was no longer downloading. (The links that had been identified in the log as being processed as TURBO_STREAM no longer were, the behavior was no longer working, and Turbo was no longer in the sources tab).

Adding a console.log(Turbo) to the application.js file makes everything work again, so I guess I'd assume that the switch to Webpacker 6 and the javascript_packs_with_chunks_tag helper somehow doesn't realize that Turbo is being used and therefore doesn't download it with the pack?

Is there a preferred way of managing this?

Thanks!

dhh commented

Sounds like Webpack is shaking its tree and not finding any usages of Turbo in the pack itself. @javan any idea how we might stop this from happening? Maybe with Webpack we shouldn't have the lib call start() itself.

I'm experiencing the same with webpacker 5.1.1. To get around it I've added a Turbo.start() call after the import, as it looks like this should have no effect beyond persuading Webpack to keep Turbo in the tree.

I'm only using javascript_pack_tag, not javascript_packs_with_chunks_tag.

javan commented

Does this "fix" it?

- import { Turbo, cable } from "@hotwired/turbo-rails"
+ import "@hotwired/turbo-rails"

Does this "fix" it?

- import { Turbo, cable } from "@hotwired/turbo-rails"
+ import "@hotwired/turbo-rails"

Yes, this works fine.

Yeah that worked for me under Webpacker 6 beta also.

Thanks, same for vite

For Turbo itself, this was not necessary, but ActionCable only worked in this way.