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

Getting Uncaught TypeError: The specifier "@hotwired/turbo-rails" was a bare specifier after upgrading to the latest version of Firefox (115.0) #191

Closed
vlasar opened this issue Jul 5, 2023 · 8 comments

Comments

@vlasar
Copy link

vlasar commented Jul 5, 2023

Hello,

After upgrading to Firefox 115.0 (64-bit), on macOS 13.4, we are seeing the following error in the console and Turbo no longer working:

Uncaught TypeError: The specifier “@hotwired/turbo-rails” was a bare specifier, but was not remapped to anything. Relative module specifiers must start with “./”, “../” or “/”.
SCR-20230705-mlzn

Honestly, I'm not sure if this is a rails/importmap-rails or a hotwired/turbo-rails issue.

# config/importmap.rb
pin "application", preload: true
pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true
pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
pin_all_from "app/javascript/controllers", under: "controllers"
// app/javascript/application.js
import { Turbo } from '@hotwired/turbo-rails'; // <- Error is raised here.

import 'controllers';

Turbo.session.drive = false;
SCR-20230705-mmfx
@RifkyLTF
Copy link

RifkyLTF commented Jul 6, 2023

I have the same issue. still looking for how to fix it

@guybedford
Copy link
Contributor

Firefox having been resolving some bugs in their native import maps implementation. Perhaps some native behaviours changed with regards to load ordering in this release. So long as the import map is loaded before the <script type="module"> or import() that is attempting to use the import map, everything should behave correctly - so that if this is a bug, a fix that alters the HTML ordering should be possible. Note that es-module-shims will not be doing anything here, so this is entirely about native import maps support.

I'd suspect it's an importmap-rails debugging issue, based on careful analysis of the load ordering to ensure the import map fully loads before any module scripts.

@vlasar
Copy link
Author

vlasar commented Jul 6, 2023

Thank you @guybedford.

We managed to resolve the issue by first rendering javascript_importmap_tags and then javascript_include_tag "application".

So, instead of doing:

<%= javascript_include_tag "application", :"data-turbo-track" => "reload" %>
<%= javascript_importmap_tags %>

we are now doing:

<%= javascript_importmap_tags %>
<%= javascript_include_tag "application", :"data-turbo-track" => "reload" %>

I'm actually surprised we had it like that and that it worked.

@mkrajewski90
Copy link

Thank you @guybedford.

We managed to resolve the issue by first rendering javascript_importmap_tags and then javascript_include_tag "application".

So, instead of doing:

<%= javascript_include_tag "application", :"data-turbo-track" => "reload" %>
<%= javascript_importmap_tags %>

we are now doing:

<%= javascript_importmap_tags %>
<%= javascript_include_tag "application", :"data-turbo-track" => "reload" %>

I'm actually surprised we had it like that and that it worked.

I have only javascript_importmap_tags in my includes but it still doesn't work :(

@grncdr
Copy link

grncdr commented Jul 13, 2023

For others experiencing this issue, it seems like a Firefox bug has been opened here: https://bugzilla.mozilla.org/show_bug.cgi?id=1842792

This comment from Dennis Schubert seems particularly relevant:

Apparently, this breaks only with the first non-module <script> tag in place. If you remove that, it works.

In my case, I had a plain <script></script> declaring some global variables before <%= javascript_importmap_tags %>. Moving that below the importmap tags caused the issue to go away.

@lumpidu
Copy link

lumpidu commented Jul 13, 2023

Seems to be a race condition of importmaps and modulepreload.

@yshmarov
Copy link

For others experiencing this issue, it seems like a Firefox bug has been opened here: https://bugzilla.mozilla.org/show_bug.cgi?id=1842792

This comment from Dennis Schubert seems particularly relevant:

Apparently, this breaks only with the first non-module <script> tag in place. If you remove that, it works.

In my case, I had a plain <script></script> declaring some global variables before <%= javascript_importmap_tags %>. Moving that below the importmap tags caused the issue to go away.

this worked for me. I moved the custom scripts and imports below <%= javascript_importmap_tags %>

@lxxxvi
Copy link

lxxxvi commented May 24, 2024

I had the same error message, but I didn't have any custom scripts or alike above <%= javascript_importmap_tags %>, so all suggestions didn't work for me.

However, in my case the turbo-rails gem was missing in the bundle 🤦, so adding

gem "turbo-rails"

to the Gemfile solved my issue.

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

8 participants