Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Migratior up function throws error when running on Bun #5348

Closed
danlannz opened this issue Mar 18, 2024 · 0 comments
Closed

Migratior up function throws error when running on Bun #5348

danlannz opened this issue Mar 18, 2024 · 0 comments

Comments

@danlannz
Copy link

When running migratior.up() on bun I'm getting migration error as MigrationClass is undefined.

MigrationError: Migration Migration20240318042632 (up) failed: Original error: undefined is not a constructor (evaluating 'new (Object.values(migration))[0](this.driver, this.config)')
 info: {
  "direction": "up",
  "name": "Migration20240318042632",
  "path": "/mikro-orm-elysia/src/migrations/Migration20240318042632.ts",
  "context": {}
}

      at new ErrorWithCause (/mikro-orm-elysia/node_modules/pony-cause/lib/error-with-cause.js:4:12)
      at new MigrationError (/mikro-orm-elysia/node_modules/umzug/lib/umzug.js:45:9)
      at /mikro-orm-elysia/node_modules/umzug/lib/umzug.js:177:31

196 |     }
197 |     resolve(params) {
198 |         const createMigrationHandler = async (method) => {
199 |             const migration = await core_1.Utils.dynamicImport(params.path);
200 |             const MigrationClass = Object.values(migration)[0];
201 |             const instance = new MigrationClass(this.driver, this.config);
                                                       ^
TypeError: undefined is not a constructor (evaluating 'new (Object.values(migration))[0](this.driver, this.config)')
      at /mikro-orm-elysia/node_modules/@mikro-orm/migrations/Migrator.js:201:50

Doing some debugging it appears that the Object.values returns an empty array from the dynamic import object on Bun

const migration = await Utils.dynamicImport(params.path!);
const MigrationClass = Object.values(migration)[0] as Constructor<Migration>;

I'm currently using the following workaround, will open a PR if this workaround is also compatible with all supported runtimes

  const migration = await Utils.dynamicImport(params.path!); 
  const fileName = params.name.split('.')[0];
  const MigrationClass = migration[fileName];
@mikro-orm mikro-orm locked and limited conversation to collaborators Mar 18, 2024
@B4nan B4nan converted this issue into discussion #5349 Mar 18, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant