Skip to content

regression file:/// import within a data: url no longer works #42860

@Pyrolistical

Description

@Pyrolistical

Version

v18.0.0

Platform

Darwin Ronalds-iMac.local 20.6.0 Darwin Kernel Version 20.6.0: Tue Feb 22 21:10:41 PST 2022; root:xnu-7195.141.26~1/RELEASE_X86_64 x86_64

Subsystem

url or module

What steps will reproduce the bug?

  1. import a data: url that itself javascript that esm imports an absolute file: url

example

import "data:text/javascript,import%20%22file:///Users/rchen/dev/projects/github.com/Pyrolistical/esm-import-file-scheme-bug/inner.js%22;";

How often does it reproduce? Is there a required condition?

always

What is the expected behavior?

inner.js is imported which prints 'inner'

What do you see instead?

crashes with

node:internal/errors:465
    ErrorCaptureStackTrace(err);
    ^

TypeError [ERR_INVALID_URL_SCHEME]: The URL must be of scheme file
    at new NodeError (node:internal/errors:372:5)
    at fileURLToPath (node:internal/url:1484:11)
    at checkIfDisallowedImport (node:internal/modules/esm/resolve:1018:23)
    at defaultResolve (node:internal/modules/esm/resolve:1147:23)
    at ESMLoader.resolve (node:internal/modules/esm/loader:605:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:318:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:80:40)
    at link (node:internal/modules/esm/module_job:78:36) {
  code: 'ERR_INVALID_URL_SCHEME'
}

Additional information

According to the documentation, esm imports within a data: url must contain absolute paths.

It is unclear what absolute paths means as there is a contradiction in the documentation:

  1. According to the section on file: absolute paths are defined as either starting with /, // or file:///.
  2. But according to esm terminology section, absolute paths start with file:///

I tested both / and file:/// within a data:, neither worked.

I tested data: url by itself with no import and there is no issue there.

This is a regression because when I tested against node 16.14.2, esm import of file: within a data: did work!

Using file: directly does work in v18. The bug only seems to be when file: is used within data:

// works
import "file:///Users/rchen/dev/projects/github.com/Pyrolistical/esm-import-file-scheme-bug/inner.js";

// fails
import "data:text/javascript,import%20%22file:///Users/rchen/dev/projects/github.com/Pyrolistical/esm-import-file-scheme-bug/inner.js%22;";

Repo where I tried various cases. See branches for different versions including v12 and v14.
https://github.com/Pyrolistical/esm-import-file-scheme-bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions