Skip to content

Does not return valid file: URLs when handling absolute paths on windows #31

@ef4

Description

@ef4

If we resolve an absolute path on windows, we get back a path that is not a valid file: URL:

import { resolve } from 'import-meta-resolve';
import { pathToFileURL } from 'url';

console.log(
  resolve(
    "C:\\Users",
    pathToFileURL("C:\\Users\\X\\")
  )
);

prints "c:\Users"
expected result: "file:///c/Users"

This is inconsistent with the behavior on posix:

import { resolve } from 'import-meta-resolve';
import { pathToFileURL } from 'url';

console.log(
  resolve(
    "/home",
    pathToFileURL("/home/x/")
  )
);

prints "file:///home"

I noticed this issue because Node will refuse to import() absolute paths on windows that are not valid file: URLs. If we're using resolve on user-provided paths and then import()ing them, it's reasonable for users to expect an absolute path to work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions