Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERR_UNSUPPORTED_ESM_URL_SCHEME on Windows with ESM #201

Closed
gigaSproule opened this issue Aug 10, 2023 · 2 comments
Closed

ERR_UNSUPPORTED_ESM_URL_SCHEME on Windows with ESM #201

gigaSproule opened this issue Aug 10, 2023 · 2 comments

Comments

@gigaSproule
Copy link

gigaSproule commented Aug 10, 2023

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)?

@wesleytodd
Copy link
Collaborator

Hey! A PR to use relative paths in this case seems reasonable. That wouldn't solve the cross drive issues, but it would the more basic problem here. Honestly that seems like a good middle ground to me.

@MikesGlitch
Copy link
Contributor

MikesGlitch commented Nov 20, 2023

@wesleytodd I put in a PR for this that imports using File URL's instead - that fixed the issue on windows for me. #202

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants