Skip to content
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

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

Open
gregg-cbs opened this issue Aug 28, 2024 · 1 comment
Open

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

gregg-cbs opened this issue Aug 28, 2024 · 1 comment

Comments

@gregg-cbs
Copy link

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.
@revolution64
Copy link

I had the same error when I was exporting multiple functions from the migration class. Made sure i'm only exporting the class that implements the MigrationInterface and it worked again for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants