Closed jdpy19 closed 4 months ago
@jdpy19 thank you for opening this issue. Could you share your app/views/layouts/application.html.erb
(mainly the line that imports application.js
or however you're loading Turbo?
I can't find it now, but I recall an issue that was previously resolved when it was determined the Turbo was not being loaded within a <script type="module">
, and that exports were polluting the global namespace.
@seanpdoyle Thank you for the response.
Here is my app/views/layouts/application.html.erb
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>
</head>
<body>
<%= render "layouts/navbar" %>
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
<%= yield %>
</body>
</html>
Narrowing this down, when I remove the import of Application
in app/javascript/controllers/application.js
the issue resolves.. which I suppose is expected.
import { Application } from "@hotwired/stimulus";
const application = Application.start();
// Configure Stimulus development experience
application.debug = false;
window.Stimulus = application;
export { application };
@jdpy19 did you add jsbundling-rails
to your Gemfile
, then execute its installation script?
The javascript_include_tag
should pass type: "module"
(as it would be generated by rails javascript:install:[bun|esbuild|rollup|webpack]
):
-<%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>
+<%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true, type: "module" %>
Ah, I pulled the application.html.erb
from another rails app. Thank you for the help!
Hey! I have spun up a new project this morning and I am running into an issue that is due to
window.fetch
being overwritten with the fetch in set operations from stimulus. FetchHotwire is using
window.fetch
which should be the native https://github.com/hotwired/turbo/blob/89be8e4c206ea877183b7ac4a89f898363a14f0f/src/http/fetch.js#L6Error
Package.json
Gemfile