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)?
When using the API (not sure if it's the same issue with the migrate CLI), node throws a
ERR_UNSUPPORTED_ESM_URL_SCHEMEerror when ESM scripts are used on Windows. It doesn't seem to like the resolved path starts withC:\or whatever letter of the drive is being used.I've pinpointed the issue to
node-migrate/lib/load-migrations.js
Line 48 in 1ed0f4c
migrationsDirectory, it is converted into an absolute path due tonode-migrate/lib/load-migrations.js
Line 18 in 1ed0f4c
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 withrequirenor 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/migrationsworks whereC:\\path\\to\\migrationsdoesn'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:\\orfile://works, so maybe that should be done when usingimport(as it breaksrequire)?