typeorm: Cannot read property 'connect' of undefined

Issue type:

[ ] question [x ] bug report [ ] feature request [ ] 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:

Configuration Options

export const test: Pool = {
  default: {
    name: 'default',
    type: 'postgres',
    host: 'localhost',
    port: 5432,
    username: 'test',
    password: '',
    database: 'main_test',
    logging: false,
    synchronize: true,
    migrations: ['db/migration/**/*{.ts,.js}'],
    subscribers: ['db/subscriber/**/*{.ts,.js}'],
    entities: ['dist/**/*.entity{.ts,.js}', 'app/**/*.entity{.ts,.js}'],
    cli: {
      migrationsDir: 'db/migration',
      subscribersDir: 'db/subscriber',
      entitiesDir: '',
    },
  },
};

Code

import supertest from 'supertest';
import { createServer } from 'http';
import { createConnection, getConnection } from 'typeorm';
import { test } from '../../config/connections';
import app from '../../app';

describe('Category - Testing', () => {
  beforeEach(async () => createConnection(test.default));
  afterEach(async () => getConnection('default').close());

  const testServer = supertest(createServer(app));

  it('responds with status code 200', async () => {
    const x = async () => {
      try {
        await testServer.get('/categories');
      } catch (err) {
        console.log(err);
      }
    };
    expect(x).toThrow();
  });
});

Error

TypeError: Cannot read property 'connect' of undefined
        at /Users/Stephano/Development/code-basket/application_6374/src/driver/postgres/PostgresDriver.ts:774:25
        at new Promise (<anonymous>)
        at PostgresDriver.Object.<anonymous>.PostgresDriver.obtainMasterConnection (/Users/Stephano/Development/code-basket/application_6374/src/driver/postgres/PostgresDriver.ts:773:16)
        at PostgresQueryRunner.Object.<anonymous>.PostgresQueryRunner.connect (/Users/Stephano/Development/code-basket/application_6374/src/driver/postgres/PostgresQueryRunner.ts:90:58)
        at PostgresQueryRunner.<anonymous> (/Users/Stephano/Development/code-basket/application_6374/src/driver/postgres/PostgresQueryRunner.ts:163:55)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 25
  • Comments: 18 (2 by maintainers)

Most upvoted comments

0.2.29 typeorm 8.5.1 pg

Same issue in runtime. But i have the db connection established. queries continue to works

Are y’all still have this issue in Typeorm 0.2.27? & with using pg 8.0.3?

I had the same issue and then managed to debug it down to the fact that I had some code that was disposing my connection prior to another TypeORM operation occurring. Worth looking at your code if this may be the culprit for some of you. The error message isn’t exactly helpful in this regard.

Same problem here, running Node 12.8.1.

@michaeldever , what version of NodeJs is running while tests has been executed? I try to rerun some tests job that in past resulted in sucess, but now, a got error. If all was currectly before, so, whats now? I checked my Ci/Cd config in .gitlab-ci.yml, and when I saw how the Node version were being downloaded (node:latest), I got an Eureka! Node 14 has been released some days ago. Doing downgrade to 12.16.2, now all jobs looks going weel again. Try this too. Waiting your results…

I think It may be an error caused by ‘pg’ lib package. Some days ago was made an new release. I’ll try a downgrade with 7.x.x version