Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation hiccup on Rails 7 with turbo-rails and importmaps #2

Open
minimul opened this issue Oct 4, 2022 · 2 comments
Open

Installation hiccup on Rails 7 with turbo-rails and importmaps #2

minimul opened this issue Oct 4, 2022 · 2 comments

Comments

@minimul
Copy link
Contributor

minimul commented Oct 4, 2022

The turbo-rails gem pins thus to the config/importmap.rb file:

pin '@hotwired/turbo-rails', to: 'turbo.min.js', preload: true

When I ran bin/importmap pin turbo_power it did pin a version of @hotwired/turbo but since I didn't want two versions of Turbo, I removed it and received this error:

Uncaught TypeError: Failed to resolve module specifier "@hotwired/turbo". Relative references must start with either "/", "./", or "../".

As a workaround, I just made a "copy" in config/importmap.rb like so:

pin '@hotwired/turbo-rails', to: 'turbo.min.js', preload: true
+pin @hotwired/turbo', to: 'turbo.min.js', preload: true

After that no problems and I've already implemented a .set_attribute() stream. 🚀

Thanks for this great gem and NPM package.

@marcoroth
Copy link
Owner

Hey @minimul, thanks for opening this issue. I'm thinking about if I can somehow solve this in the library itself.

But I think there is no "sane" way that just works automatically with Import Maps. We probably need to rely on better installation instructions in the README.

@minimul
Copy link
Contributor Author

minimul commented Oct 6, 2022

In one regard it does work out of the box because it does install the dependency. e.g.

$ bin/importmap pin turbo_power
Pinning "turbo_power" to https://ga.jspm.io/npm:turbo_power@0.1.3/dist/index.js
Pinning "@hotwired/turbo" to https://ga.jspm.io/npm:@hotwired/turbo@7.2.0/dist/turbo.es2017-esm.js

Yes, you then have two versions of Turbo, which is not desired, but it should work out of the box.

Perhaps that awareness alone can go into the README. Or my alternate hack too.

FWIW:
I didn't have to mess with the stock app/javascript/application.js either:

import '@hotwired/turbo-rails'
import 'controllers'
+ import TurboPower from 'turbo_power'
+ TurboPower.initialize(Turbo.StreamActions)

In short, I didn't have modify to do a import * as Turbo from '@hotwired/turbo' or import { Turbo } from '@hotwired/turbo' or those same import statements w/ @hotwired/turbo-rails and Turbo Power works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants