Closed olivierlacan closed 2 years ago
Expected errors from using the es-module-shim
While import maps are native in Chrome and Edge, they need a shim in other browsers that'll produce a JavaScript console error like
TypeError: Module specifier, 'application' does not start with "/", "./", or "../".
. This error is normal and does not have any user-facing consequences.
https://github.com/rails/importmap-rails#expected-errors-from-using-the-es-module-shim
In browsers without import maps support, a console error will be given:
Uncaught TypeError: Failed to resolve module specifier "app". Relative references must start with either "/", "./", or "../". at <anonymous>:1:15
This execution failure is a feature - it avoids the polyfill causing double execution. The first import being a bare specifier in the pattern above is important to ensure this.
This is because the polyfill cannot disable the native loader - instead it will only execute modules that would otherwise fail resolving or parsing to avoid duplicate fetches or executions that would cause performance and reliability issues.
Expected errors from using the es-module-shim
While import maps are native in Chrome and Edge, they need a shim in other browsers that'll produce a JavaScript console error like
TypeError: Module specifier, 'application' does not start with "/", "./", or "../".
. This error is normal and does not have any user-facing consequences.https://github.com/rails/importmap-rails#expected-errors-from-using-the-es-module-shim
In browsers without import maps support, a console error will be given:
Uncaught TypeError: Failed to resolve module specifier "app". Relative references must start with either "/", "./", or "../". at <anonymous>:1:15
This execution failure is a feature - it avoids the polyfill causing double execution. The first import being a bare specifier in the pattern above is important to ensure this. This is because the polyfill cannot disable the native loader - instead it will only execute modules that would otherwise fail resolving or parsing to avoid duplicate fetches or executions that would cause performance and reliability issues.
Hi, sorry for butting into this issue like this, but I need to get to the bottom of a really specific question and this comment by @dmcge is highly relevant.
The behavior described above is completely consistent with what I'm seeing, that is to say:
The one issue I have is that on Safari, the javascript on the page stops working if its devtools are open. I am concerned that I will never be able to actually debug the app at all under safari. Is this expected behavior? If so, is there any timeline for improving this situation? Or maybe a setting in Safari Devtools to make it not break itself? Or is there something I might be doing wrong in using the shim to make Safari Devtools work again?
I can offer any three.js example page (https://threejs.org/examples/#webgl_animation_keyframes) as a reproduction for this Safari problem. Firefox has no such issue.
---- Update: Actually it seems like potentially all that was happening was that the page's scripting does not start working until you wait a litlte bit if the devtools are open. I guess this whole thing is a false alarm. Sorry.
I am following the tutorial. I've reached the chapter, where the tutorial introduces to turbo for a delete method. Turbo did not work (on Firefox) until I've fixed this JavaScript problem.
Like the error asked, I added "./" to all relative imports under javascript directory. Once I've done that, turbo pop up appeared after I clicked on Delete and allowed me to delete the article, like the tutorial expects.
Can you confirm that this is indeed not "user facing"?
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?
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?
Hi @skd. If removing import "controllers"
is a temporary fix, what would be a permanent fix? I'm dealing with the same problem.
i have the same issue but with
i only set up my app server with bin/rails server -b 0.0.0.0
TypeError: Module specifier, 'application' does not start with "/", "./", or "../". Referenced from http://192.168.0.122:3000/ es-module-shims.js:34
I ran into this issue as well, same error. However, I have some custom JS in controllers that I needed so I cannot just comment it out. I moved this line:
pin_all_from "app/javascript/controllers", under: "controllers"
to be the last line in my config/importmap.rb and restarted my bin/dev process and the issue was gone. I don't know if ordering of the pin statements would be important or just making a dummy change to the importmap.rb file and reloading fixed it. But, just wanted to pass that along to anyone running into this problem.
FYI, I'm using Rails 7.0.6 and ruby 3.2.2
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.
IIRC I solved this by renaming app/assets/javascripts/application.js
to app/assets/javascripts/application-old.js
and updating the include:
<%= javascript_include_tag 'application-old' %>
Not the best solution, but the plan is to over time migrate the code in application-old.js
elsewhere.
@rejeep Thanks, i'll give this a shot
Inserting es-modules-shims
before javascript_importmap_tags
as mentioned in the importmaps-rails readme resolved this issue for me for legacy browsers
<script async src="https://ga.jspm.io/npm:es-module-shims@1.8.2/dist/es-module-shims.js" data-turbo-track="reload"></script>
<%= javascript_importmap_tags %>
See "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
Even with the es-module-shims, my JS still won't load
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: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
config/importmap.rb
$ bin/importmap json
:app/views/layouts/application.html.erb
:app/javascript/application.js
: