Closed Bug 1777450 Opened 3 years ago Closed 3 years ago

Confusing error message when using dynamic import with relative paths when the referrer does not have a valid URL

Categories

(Core :: JavaScript Engine, defect, P2)

Firefox 101
defect

Tracking

()

RESOLVED FIXED
104 Branch
Tracking Status
firefox-esr91 --- wontfix
firefox-esr102 --- wontfix
firefox102 --- wontfix
firefox103 --- wontfix
firefox104 --- fixed

People

(Reporter: nicolo.ribaudo, Assigned: jonco)

References

(Blocks 1 open bug, Regression)

Details

(Keywords: regression)

Attachments

(1 file)

Consider this JavaScript file:

const p = await import(`data:text/javascript,
  export default import("./foo.js");
`);

await p.default;

It throws this error:

Uncaught TypeError: Error resolving module specifier “./foo.js”. Relative module specifiers must start with “./”, “../” or “/”.

which is super confusing, because ./foo.js starts with ./.

The same happens if you go to the about:blank page and run await import("./foo.js") in the console.

I believe that this happens because the referrer (the "base" from where ./foo.js is resolved) in both cases is not a valid URL: in the first example it's probably the source of the inline imported module, while in the second case it's probably about:blank.

PS: I'm not sure if the component for this bug report should be "DOM: Core & HTML" or "JavaScript Engine"

this is not really a javascript engine bug, but since bug 1566307 was filed such, moving also this Core: Javascript Engine.

Component: DOM: Core & HTML → JavaScript Engine

Set release status flags based on info from the regressing bug 1566307

:jonco, since you are the author of the regressor, bug 1566307, could you take a look?
For more information, please visit auto_nag documentation.

Flags: needinfo?(jcoppeard)

Is this problem can be described as:
import("./foo.js"); // where ./foo.js is a non-exist file

And the error message should be
"TypeError: Error resolving module specifier: ./foo.js" ?

(Without the 'Relative module specifiers must start with “./”, “../” or “/”.')

If that's so, then I could just add another error message for that.
https://searchfox.org/mozilla-central/rev/4654ce1e24a6af17bc96ab60f1f70c218755142f/dom/locales/en-US/chrome/dom/dom.properties#325

If I run import("./foo.js") where foo.js does not exist I already get a good error:

TypeError: error loading dynamically imported module

The specifier could be resolved, the problem in this case is that there is no file corresponding to the resolved specifier ("resolving the specifier" happens before trying a network request). I don't think that the error needs to be updated in this case.

Blocks: jserror
Severity: -- → S4
Priority: -- → P2
Assignee: nobody → jcoppeard
Flags: needinfo?(jcoppeard)

This fixes the original case by adding an extra error reason which is used when
the specifier could be bare and and only warning about relative URLs in this
case.

The same problem happens with import maps enable where "./foo.js" produces an
error about it being a bare specifier, which it's not. For that case make
ParseURLLikeImportSpecifier return a ResolveResult and use the same approach.

Attachment #9284366 - Attachment description: Bug 1777450 - Separate error messages for module resulution failure when the specifier might be bare r?allstarschh → Bug 1777450 - Separate error messages for module resulution failure when the specifier might be bare r=allstarschh!,flod!
Pushed by jcoppeard@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/b716f36c4a1c Separate error messages for module resulution failure when the specifier might be bare r=allstarschh,flod
Status: NEW → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 104 Branch

The patch landed in nightly and beta is affected.
:jonco, is this bug important enough to require an uplift?

  • If yes, please nominate the patch for beta approval.
  • If no, please set status-firefox103 to wontfix.

For more information, please visit auto_nag documentation.

Flags: needinfo?(jcoppeard)

No, we can let this ride the trains.

Flags: needinfo?(jcoppeard)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: