(This applies to Rails 7.1, Turbo 8.0 with esbuild and propshaft)
If you're getting a "TypeError: map.get is not a function" when navigating between pages:
Uncaught (in promise) TypeError: map.get is not a function
at fetch (application-df30cd29ded7227ed5c827c81fa4fc9b51db518a.js:6485:20)
at fetchWithTurboHeaders (application-df30cd29ded7227ed5c827c81fa4fc9b51db518a.js:1153:10)
at FetchRequest.perform (application-df30cd29ded7227ed5c827c81fa4fc9b51db518a.js:1263:25)
fetch @ application-df30cd29ded7227ed5c827c81fa4fc9b51db518a.js:6485
fetchWithTurboHeaders @ application-df30cd29ded7227ed5c827c81fa4fc9b51db518a.js:1153
perform @ application-df30cd29ded7227ed5c827c81fa4fc9b51db518a.js:1263
await in perform (async)
issueRequest @ application-df30cd29ded7227ed5c827c81fa4fc9b51db518a.js:2587
visitStarted @ application-df30cd29ded7227ed5c827c81fa4fc9b51db518a.js:2839
start @ application-df30cd29ded7227ed5c827c81fa4fc9b51db518a.js:2543
startVisit @ application-df30cd29ded7227ed5c827c81fa4fc9b51db518a.js:3260
visitProposedToLocation @ application-df30cd29ded7227ed5c827c81fa4fc9b51db518a.js:2831
visitProposedToLocation @ application-df30cd29ded7227ed5c827c81fa4fc9b51db518a.js:4751
proposeVisit @ application-df30cd29ded7227ed5c827c81fa4fc9b51db518a.js:3251
visit @ application-df30cd29ded7227ed5c827c81fa4fc9b51db518a.js:4654
followedLinkToLocation @ application-df30cd29ded7227ed5c827c81fa4fc9b51db518a.js:4743
clickBubbled @ application-df30cd29ded7227ed5c827c81fa4fc9b51db518a.js:1919
The issue seems to be that, for some reason, Turbo/Stimulus is using a wrong fetch()
:
I did not dig deep into the bundling process to understand what's happening, but the following change fixed it for me:
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index fddc2f5..9b2bb31 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -6,8 +6,8 @@
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
- <%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>
+ <%= javascript_include_tag "application", "data-turbo-track": "reload", type: "module" %>
Thanks!