镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

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

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

Activity

  1. changed the title [-]regression file: import within a data: url no longer works[/-] [+]regression `file:` import within a `data:` url no longer works[/+] on Apr 25, 2022
  2. changed the title [-]regression `file:` import within a `data:` url no longer works[/-] [+]regression `file:///` import within a `data:` url no longer works[/+] on Apr 25, 2022
  3. Pyrolistical commented on Apr 25, 2022

    @Pyrolistical
    Author

    I've bitsected the node versions, the regression was introduced in 17.5.0. it worked fine in 17.4.0

  4. Pyrolistical commented on Apr 25, 2022

    @Pyrolistical
    Author

    i've traced the code and i believe by the time the url is passed into https://github.com/nodejs/node/blob/master/lib/internal/modules/esm/module_job.js#L56 it is already missing file:///.

  5. added a commit that references this issue on Apr 27, 2022
  6. added a commit that references this issue on May 2, 2022
  7. added a commit that references this issue on Jul 12, 2022
  8. added a commit that references this issue on Jul 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions