Hotwire Discussion

Turbo is not defined when trying to call Turbo.visit inside a stimulus controller

Hey guys,
Im using the rails pipeline with not webpack
I have a stimulus controller
I have gem ‘hotwire-rails’ on my Gemfile
All is working well, except when I trying call Turbo.visit on stimulus controller.

I saw here the js is exporting the Turbo object, but different from ‘stimulus’ its not possible to import stuffs from ‘turbo’

import { Controller } from “stimulus” // Works
import { Turbo } from ‘turbo’ // not works

any ideia how access Turbo on assets pipeline?

Thanks

updated:

Found the problem here:

I’m having a similar problem except I am using webpacker.

if using webpacker
does not import { Turbo } from "@hotwired/turbo-rails" works as expected?

I just added import "@hotwired/turbo-rails" to my application.js as per the install script:

And am also now using import { Turbo } from "@hotwired/turbo-rails" in my stimulus controller as per the readme.

It does seem to work but I get the “Turbo is not defined error” if I try to step through my code.

just tu check, are you using stimulus controller inside webpack ecosystem right (and not on app/assets/javascript)?

Yes, using webpack. My stimulus controllers are in app/javascript/controllers

its pretty weird then
I will try to move it to webpack and check