mongo-migrate-ts icon indicating copy to clipboard operation
mongo-migrate-ts copied to clipboard

TypeError: classes[key] is not a constructor

Open gregg-cbs opened this issue 5 months ago • 1 comments

Hi,

When running migrate:up - we are getting the error TypeError: classes[key] is not a constructor. The error is coming from node_modules/mongo-migrate-ts/lib/migrations.ts 38:19.

This error could be due to something in our code but we cannot see where or what because the migrations.ts is not forwarding the error. We have removed all our code from migrations and still see this error.

Our config is as follows and we can confirm this worked at some point but as of late it started throwing the above error.

package.json:

  "scripts": {
    "migrate:up": "ts-node ./src/api/common/database/migrations/index.ts up",
    "migrate:down": "ts-node ./src/api/common/database/migrations/index.ts down"
  },
// file: /migrations/index.ts
import { mongoMigrateCli } from "mongo-migrate-ts"; // v1.6.2

const config = {
  db: "our_db",
  mongoUri: "mongodb+srv://"
};

mongoMigrateCli({
  database: config.db,
  uri: config.mongoUri,
  migrationsDir: '.', // Directory where your migration files are stored
  migrationsCollection: 'migrations', // Collection to store migration status
});

Full Error:

✖ Error executing migrations
Example app listening on port 3000
TypeError: classes[key] is not a constructor
    at /Users/yser/Documents/projects/cbs/project-v3/node_modules/.pnpm/[email protected][email protected]/node_modules/mongo-migrate-ts/lib/migrations.ts:38:19
    at Array.map (<anonymous>)
    at loadMigrationFile (/Users/yser/Documents/projects/cbs/project-v3/node_modules/.pnpm/[email protected][email protected]/node_modules/mongo-migrate-ts/lib/migrations.ts:34:6)
    at async Promise.all (index 2)
    at async loadMigrations (/Users/yser/Documents/projects/cbs/project-v3/node_modules/.pnpm/[email protected][email protected]/node_modules/mongo-migrate-ts/lib/migrations.ts:51:22)
    at async up (/Users/yser/Documents/projects/cbs/project-v3/node_modules/.pnpm/[email protected][email protected]/node_modules/mongo-migrate-ts/lib/commands/up.ts:38:27)
    at async Command.<anonymous> (/Users/yser/Documents/projects/cbs/project-v3/node_modules/.pnpm/[email protected][email protected]/node_modules/mongo-migrate-ts/lib/cli.ts:57:11)
 ELIFECYCLE  Command failed with exit code 1.

gregg-cbs avatar Aug 28 '24 09:08 gregg-cbs