mlly
mlly copied to clipboard
mlly throws `[error] The URL must be of scheme file` when called with absolute path on windows
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'] }
)
Additional context
originally encountered in https://github.com/nuxt/nuxt/pull/30540
Logs
No response
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.
For reference, upstream bug in https://github.com/wooorm/import-meta-resolve/issues/31