importmap-rails: TypeError: Module specifier, 'application' does not start with "/", "./", or "../".
Getting this with a fresh Rails 7.0.2.3 app with import maps installed in macOS Safari Version 15.1 (17612.2.9.1.20).
For context the exported <script> for import maps:
<script type="importmap" data-turbo-track="reload">{
"imports": {
"application": "/assets/application-37f365cbecf1fa2810a8303f4b6571676fa1f9c56c248528bc14ddb857531b95.js",
"@hotwired/turbo-rails": "/assets/turbo.min-96cbf52c71021ba210235aaeec4720012d2c1df7d2dab3770cfa49eea3bb09da.js",
"@hotwired/stimulus": "/assets/stimulus.min-900648768bd96f3faeba359cf33c1bd01ca424ca4d2d05f36a5d8345112ae93c.js",
"@hotwired/stimulus-loading": "/assets/stimulus-loading-1fc59770fb1654500044afd3f5f6d7d00800e5be36746d55b94a2963a7a228aa.js",
"controllers/application": "/assets/controllers/application-368d98631bccbf2349e0d4f8269afb3fe9625118341966de054759d96ea86c7e.js",
"controllers/hello_controller": "/assets/controllers/hello_controller-549135e8e7c683a538c3d6d517339ba470fcfb79d62f738a0a089ba41851a554.js",
"controllers": "/assets/controllers/index-2db729dddcc5b979110e98de4b6720f83f91a123172e87281d5a58410fc43806.js"
}
}</script>
Hard to diagnose since it doesn’t include any stack traces. Seems potentially related to https://github.com/guybedford/es-module-shims/issues/244 but I wasn’t sure whether to escalate quite yet.
Gemfile
gem "importmap-rails"
config/importmap.rb
# Pin npm packages by running ./bin/importmap
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"
$ bin/importmap json:
$ bin/importmap json
{
"imports": {
"application": "/assets/application-37f365cbecf1fa2810a8303f4b6571676fa1f9c56c248528bc14ddb857531b95.js",
"@hotwired/turbo-rails": "/assets/turbo.min-96cbf52c71021ba210235aaeec4720012d2c1df7d2dab3770cfa49eea3bb09da.js",
"@hotwired/stimulus": "/assets/stimulus.min-900648768bd96f3faeba359cf33c1bd01ca424ca4d2d05f36a5d8345112ae93c.js",
"@hotwired/stimulus-loading": "/assets/stimulus-loading-1fc59770fb1654500044afd3f5f6d7d00800e5be36746d55b94a2963a7a228aa.js",
"controllers/application": "/assets/controllers/application-368d98631bccbf2349e0d4f8269afb3fe9625118341966de054759d96ea86c7e.js",
"controllers/hello_controller": "/assets/controllers/hello_controller-549135e8e7c683a538c3d6d517339ba470fcfb79d62f738a0a089ba41851a554.js",
"controllers": "/assets/controllers/index-2db729dddcc5b979110e98de4b6720f83f91a123172e87281d5a58410fc43806.js"
}
}
app/views/layouts/application.html.erb:
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<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_importmap_tags %>
</head>
<body>
<main>
<%= yield %>
</main>
</body>
</html>
app/javascript/application.js:
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
import "@hotwired/turbo-rails"
import "controllers"
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 4
- Comments: 15 (1 by maintainers)
why is this issue closed?
This issue is still persistent. Anyone have a working solution that they can share? Commenting out import “controllers”; is not an option.
Hi @skd. If removing
import "controllers"is a temporary fix, what would be a permanent fix? I’m dealing with the same problem.The offending import is
import "controllers". Commenting it out also fixes the problem. Maybe the root problem in my case (creating a project from scratch following the tutorial) is poorly configured controllers javascript package for the default empty project?Inserting
es-modules-shimsbeforejavascript_importmap_tagsas mentioned in the importmaps-rails readme resolved this issue for me for legacy browsersSee “Supporting legacy browsers such as Safari on iOS 15” here: https://github.com/rails/importmap-rails?tab=readme-ov-file#supporting-legacy-browsers-such-as-safari-on-ios-15
i have the same issue but with
i only set up my app server with
bin/rails server -b 0.0.0.0TypeError: Module specifier, 'application' does not start with "/", "./", or "../". Referenced from http://192.168.0.122:3000/ es-module-shims.js:34Had an issue with this recently.
Everything had been fine for 8 months then all of a sudden I had customer complaints.
The issue was that in addition to the
es-module-shimI had also added another script tag abovejavascript_importmap_tags.As soon as I had moved any script tag that wasn’t
es-module-shimsbelowjavascript_importmap_tagsthe issue was resolved.It seems the order must be
Even with the es-module-shims, my JS still won’t load
IIRC I solved this by renaming
app/assets/javascripts/application.jstoapp/assets/javascripts/application-old.jsand updating the include:Not the best solution, but the plan is to over time migrate the code in
application-old.jselsewhere.