TypeError: someClass is not a constructor

See original GitHub issue

Issue type:

[ ] question [x] bug report [ ] feature request [x] documentation issue

Database system/driver:

[ ] cordova [ ] mongodb [ ] mssql [ ] mysql / mariadb [ ] oracle [x] postgres [ ] cockroachdb [ ] sqlite [ ] sqljs [ ] react-native [ ] expo

TypeORM version:

[x] latest [ ] @next [ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

I have been trying for hours to generate a migration, but seems that everything is leading to a typeorm error

this is my Entity

import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn } from "typeorm";

@Entity()
export class CommentEntity {
  @PrimaryGeneratedColumn()
  id!: number;

  @CreateDateColumn()
  createdAt!: Date;

  @UpdateDateColumn()
  updatedAt!: Date;

  @Column()
  userNickname!: string;

  @Column()
  content!: string;
}

this is my ormconfig.json

{
   "type": "postgres",
   "host": "localhost",
   "port": 5432,
   "username": "postgres",
   "password": "",
   "database": "postgres",
   "logging": false,
   "entities": [
      "modules/comments/CommentEntity.ts"
   ],
   "migrations": [
      "migrations/*.ts"
   ],
   "cli": {
      "migrationsDir": "migrations"
   }
}

and then I run

./node_modules/.bin/ts-node ./node_modules/typeorm/cli.js migration:generate -n Comment

this is the output of the script

TypeError: someClass is not a constructor
    at class_1.get (/home/user/Development/myapp/src/src/container.ts:34:51)
    at Object.getFromContainer (/home/user/Development/myapp/src/src/container.ts:71:29)
    at /home/user/Development/myapp/src/src/connection/ConnectionMetadataBuilder.ts:35:58
    at Array.map (<anonymous>)
    at ConnectionMetadataBuilder.buildMigrations 
    (/home/user/Development/myapp/src/src/connection/ConnectionMetadataBuilder.ts:35:36)
    at Connection.buildMetadatas (/home/user/Development/myapp/src/src/connection/Connection.ts:520:54)
    at Connection.<anonymous> (/home/user/Development/myapp/src/src/connection/Connection.ts:191:18)
    at step (/home/user/Development/myapp/src/node_modules/tslib/tslib.js:136:27)
    at Object.next (/home/user/Development/myapp/src/node_modules/tslib/tslib.js:117:57)
    at fulfilled (/home/user/Development/myapp/src/node_modules/tslib/tslib.js:107:62)

I have tried for a full text search on my IDE for someClass because it looks like some kind of placeholder for testing that someone forgot in the code, but there was nothing.

Thanks

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:8
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

14reactions
DimosthenisKcommented, Feb 7, 2020

I KNEW I had seen that before. Take a look at my previous issue: https://github.com/typeorm/typeorm/issues/5079

You have a file inside your migrations dir that isn’t a TS file or doesn’t match your migration file glob pattern

4reactions
kaushiksamantacommented, Feb 17, 2020

This is the correct way to initialize migrations and entities:- (https://github.com/nrwl/nx/issues/803)

import * as entities from './src/entities';

const contexts = (require as any).context('../../apps/api/src/migrations/', true, /\.ts$/);
const migrations = contexts.keys()
  .map(modulePath => contexts(modulePath))
  .reduce((result, migrationModule) => {
    result.concat(Object.keys(migrationModule).map(key => migrationModule[key]), [])
  });

export const dbConfig: TypeOrmModuleOptions = {
  type: 'postgres',
  host: process.env.POSTGRES_HOST,
  port: Number(process.env.POSTGRES_PORT),
  username: process.env.POSTGRES_USER,
  password: process.env.POSTGRES_PASSWORD,
  database: process.env.POSTGRES_DATABASE,
  entities: Object.values(entities),
  synchronize: false,
  migrationsRun: true,
  logging: true,
  migrations: Object.values(migrations)
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: "x" is not a constructor - JavaScript - MDN Web Docs
The JavaScript exception "is not a constructor" occurs when there was an attempt to use an object or a variable as a constructor,...
Read more >
Why Does This Typescript Output "[Class] is not a constructor."?
This error message means that [Class] is not initialized by the time a call to its constructor is ...
Read more >
typeorm/typeorm - Gitter
I'm not in a position where I can create new tables outside of these store ... TypeError: Class extends value undefined is not...
Read more >
TypeError: "X" is not a constructor in JavaScript | bobbyhadz
To solve the "TypeError: 'X' is not a constructor" in JavaScript, make sure to only use the new operator on valid constructors, e.g....
Read more >
Python Class Constructors: Control Your Object Instantiation
In this tutorial, you'll learn how class constructors work in Python. ... TypeError: __init__() should return None, not 'int'.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found