mlly icon indicating copy to clipboard operation
mlly copied to clipboard

mlly throws `[error] The URL must be of scheme file` when called with absolute path on windows

Open danielroe opened this issue 1 year ago • 2 comments

Environment

windows mlly 1.7.3

Reproduction

https://github.com/danielroe/windows-reproductions/pull/1

Describe the bug

When called with an absolute path on Windows, resolvePathSync fails.

Sample code:

import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'

import { resolvePathSync } from 'mlly'

resolvePathSync(
  resolve(fileURLToPath(import.meta.url), '../plugins/router'))
  { extensions: ['.ts', '.js'] }
)

full reproduction

Additional context

originally encountered in https://github.com/nuxt/nuxt/pull/30540

Logs

No response

danielroe avatar Jan 12 '25 12:01 danielroe

Node.js ESM resolve requires that Windows absolute paths (same limit of imports) have file proto.

I think for resolvePathSync wrapper we could identify windows absolute paths and do renormalization to avoid this issue.

pi0 avatar Jan 12 '25 22:01 pi0

For reference, upstream bug in https://github.com/wooorm/import-meta-resolve/issues/31

mrginglymus avatar Sep 02 '25 11:09 mrginglymus