"An import map is added after module script load was triggered"
lpknv opened this issue · 1 comments
After creating a fresh rails 7.2 app and following the guide on Selectively importing modules, I faced an error in the browser console:
An import map is added after module script load was triggered. Uncaught TypeError: Failed to resolve module specifier "sigpad". Relative references must start with either "/", "./", or "../". edit:1 Uncaught TypeError: Failed to resolve module specifier "application". Relative references must start with either "/", "./", or "../". edit:1 Uncaught TypeError: Failed to resolve module specifier "sigpad". Relative references must start with either "/", "./", or "../".
That error happened after reloading the browsers window manually via Ctrl + R. Before the manual reload I had no errors.
I can provide you with my code below:
The importmap.rb
file:
pin "application"
pin "@hotwired/turbo-rails", to: "turbo.min.js"
pin "@hotwired/stimulus", to: "stimulus.min.js"
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js"
pin_all_from "app/javascript/controllers", under: "controllers"
pin "sigpad", preload: false #<-- as in the guides shown
edit.html.erb
<% content_for :head do %>
<%= javascript_import_module_tag "sigpad" %>
<% end %>
sigpad.js
console.log('logging!!!!!!!!!');
application.html.erb
...
<head>
<%= stylesheet_link_tag "tailwind", "inter-font", "data-turbo-track": "reload" %>
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<%= javascript_importmap_tags %>
<%= yield(:head) %>
</head>
...
I really hope that I am missing some important detail. I do appreciate all the help!
I think I can close this issue now. The errors appeared because I accidentally had yield(:head)
twice in my code. Oops...