Skip to content

Migrator assumes running as a ESModule #142

@TheDevMinerTV

Description

@TheDevMinerTV

The migrator assumes that it can use import here: https://github.com/tim-smart/sqlfx/blob/main/packages/sql/src/Migrator/Node.ts#L32
This makes the migrator fail in projects that haven't migrated over to ESM yet.

This also breaks on Windows where the following code breaks loading:

const MigratorLive = Layer.provide(
	PgLive,
	Migrator.makeLayer({
		loader: Migrator.fromDisk(fileURLToPath(new URL('migrations', import.meta.url))),
		schemaDirectory: 'src/migrations'
	})
);

which fails with:

node:internal/process/promises:288
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[Error: {"reason":"import-error","message":"Could not import migration \"1_init\"\n\nError [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:'","_tag":"MigrationError"}] {
  toJSON: [Function (anonymous)],
  toString: [Function (anonymous)],
  [Symbol(effect/Runtime/FiberFailure)]: Symbol(effect/Runtime/FiberFailure),
  [Symbol(effect/Runtime/FiberFailure/Cause)]: {
    _tag: 'Parallel',
    left: { _tag: 'Empty' },
    right: {
      _tag: 'Fail',
      error: {
        reason: 'import-error',
        message: 'Could not import migration "1_init"\n' +
          '\n' +
          "Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:'",
        _tag: 'MigrationError'
      }
    }
  },
  [Symbol(nodejs.util.inspect.custom)]: [Function (anonymous)]
}

Related: nodejs/node#31710 nodejs/node#34765

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