Skip to content

Instantly share code, notes, and snippets.

@pch
Created February 2, 2024 07:51
Show Gist options
  • Save pch/fe276b29ba037bdaeaa525932478ca18 to your computer and use it in GitHub Desktop.
Save pch/fe276b29ba037bdaeaa525932478ca18 to your computer and use it in GitHub Desktop.
Rails, Turbo, esbuild: TypeError: map.get is not a function

(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():

https://github.com/hotwired/stimulus/blob/bafb739401f54fed1b70869410979b5acd43f487/src/multimap/set_operations.ts#L10

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" %>
@1wilber
Copy link

1wilber commented Jul 1, 2024

Thanks!

@das412
Copy link

das412 commented Jul 10, 2024

Thank you!

@MiroBabic
Copy link

thank you!

@pangui
Copy link

pangui commented Aug 12, 2024

Thank you!!

@kirillshevch
Copy link

thanks!

@fernandollisboa
Copy link

thank youuuuu

@rolandoalvarado
Copy link

Thank you solve my problem too.

@EverardB
Copy link

EverardB commented Sep 1, 2024

Indeed... Thanks for posting this
Problem solved

@asmega
Copy link

asmega commented Jan 20, 2025

👍

@pethl
Copy link

pethl commented Feb 6, 2025

wow - thanks for posting. I introduced this error trying to fix something else, spent HOURS on another problem that this was causing, then finally found your post while trying to fix yet another issue it caused. People like you deserve medals.

@juliandavidmr
Copy link

Thanks! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment