Skip to content

TypeError: classes[key] is not a constructor #116

@gregg-cbs

Description

@gregg-cbs

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/mongo-migrate-ts@1.6.2_mongodb@6.8.0/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/mongo-migrate-ts@1.6.2_mongodb@6.8.0/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/mongo-migrate-ts@1.6.2_mongodb@6.8.0/node_modules/mongo-migrate-ts/lib/migrations.ts:51:22)
    at async up (/Users/yser/Documents/projects/cbs/project-v3/node_modules/.pnpm/mongo-migrate-ts@1.6.2_mongodb@6.8.0/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/mongo-migrate-ts@1.6.2_mongodb@6.8.0/node_modules/mongo-migrate-ts/lib/cli.ts:57:11)
 ELIFECYCLE  Command failed with exit code 1.

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