Skip to content

ERR_UNSUPPORTED_ESM_URL_SCHEME on Windows with ESM #201

@gigaSproule

Description

@gigaSproule

When using the API (not sure if it's the same issue with the migrate CLI), node throws a ERR_UNSUPPORTED_ESM_URL_SCHEME error when ESM scripts are used on Windows. It doesn't seem to like the resolved path starts with C:\ or whatever letter of the drive is being used.

I've pinpointed the issue to

mod = await import(filepath)
. Even when I pass in a relative path for the migrationsDirectory, it is converted into an absolute path due to
const migrationsDirectory = path.resolve(opts.migrationsDirectory || 'migrations')
.

I'm not sure what the solution is, as it's node not working with absolute paths on Windows with import. This isn't an issue with require nor is it an issue with an absolute path on MacOS or Linux.

I've tried a few different scenarios in the REPL, and using a POSIX path in Windows does work (e.g. using /path/to/migrations works where C:\\path\\to\\migrations doesn't). But obviously that doesn't help if the migrations directory is on a different mapped drive.

I was struggling to see where this issue was coming from, so I thought it was at least useful to raise something here in case someone else comes across this.

Related Node issue nodejs/node#31710.

Prefixing the path with file:\\ or file:// works, so maybe that should be done when using import (as it breaks require)?

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