Skip to content

esm: improve error when calling `import.meta.resolve` from `data:` URL

Not sure about the error code (ERR_UNSUPPORTED_RESOLVE_REQUEST). For reference, here are what error message other runtimes emit when doing import('data:text/javascript,export default import.meta.resolve("bare-package-name")').catch(console.error):

  • Chromium: TypeError: Failed to execute 'resolve' on 'import.meta': Failed to resolve module specifier bare-package-name: Relative references must start with either "/", "./", or "../".
  • Safari: TypeError: Module name, 'bare-package-name' does not resolve to a valid URL.
  • Firefox: TypeError: The specifier “bare-package-name” was a bare specifier, but was not remapped to anything. Relative module specifiers must start with “./”, “../” or “/”.
  • Deno: TypeError: Relative import path "bare-package-name" not prefixed with / or ./ or ../
  • Node.js with this PR: TypeError [ERR_UNSUPPORTED_RESOLVE_REQUEST]: Failed to resolve module specifier "bare-package-name" from "data:text/javascript,export default import.meta.resolve("bare-package-name")": Invalid relative url or base scheme is not hierarchical.

Here are the error messages for import('data:text/javascript,export default import.meta.resolve("./relative")').catch(console.error):

  • Chromium: TypeError: Failed to execute 'resolve' on 'import.meta': Failed to resolve module specifier ./relative: Invalid relative url or base scheme isn't hierarchical.
  • Safari: TypeError: Module name, './relative' does not resolve to a valid URL
  • Firefox: TypeError: Error resolving module specifier “./relative”.
  • Deno: TypeError: invalid URL: relative URL with a cannot-be-a-base base
  • Node.js with this PR: TypeError [ERR_UNSUPPORTED_RESOLVE_REQUEST]: Failed to resolve module specifier "./relative" from "data:text/javascript,export default import.meta.resolve("./relative")": Invalid relative url or base scheme is not hierarchical.

Merge request reports

Loading