typeorm: MissingDriverError: Wrong driver: "undefined" given.

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:

I’m trying to run migrations, however, using the same ORM connection options that work on the server, the CLI throws:

MissingDriverError: Wrong driver: "undefined" given. Supported drivers are: "cordova", "expo", "mariadb", "mongodb", "mssql", "mysql", "oracle", "postgres", "sqlite", "sqljs", "react-native".
    at new MissingDriverError (/home/feimosi/Projects/saycaster-podcatcher/backend/src/error/MissingDriverError.ts:8:9)
    at DriverFactory.create (/home/feimosi/Projects/saycaster-podcatcher/backend/src/driver/DriverFactory.ts:55:23)
    at new Connection (/home/feimosi/Projects/saycaster-podcatcher/backend/src/connection/Connection.ts:125:43)
    at ConnectionManager.create (/home/feimosi/Projects/saycaster-podcatcher/backend/src/connection/ConnectionManager.ts:64:28)
    at Object.<anonymous> (/home/feimosi/Projects/saycaster-podcatcher/backend/src/index.ts:223:35)
    at step (/home/feimosi/Projects/saycaster-podcatcher/backend/node_modules/tslib/tslib.js:133:27)
    at Object.next (/home/feimosi/Projects/saycaster-podcatcher/backend/node_modules/tslib/tslib.js:114:57)
    at /home/feimosi/Projects/saycaster-podcatcher/backend/node_modules/tslib/tslib.js:107:75
    at new Promise (<anonymous>)
    at Object.__awaiter (/home/feimosi/Projects/saycaster-podcatcher/backend/node_modules/tslib/tslib.js:103:16)

I run it with the following command (based on this article): ts-node ./node_modules/typeorm/cli -f ./src/orm.config.ts

I’m sure type: 'postgres' property is set. Am I missing something?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 13
  • Comments: 32 (2 by maintainers)

Commits related to this issue

Most upvoted comments

solved it by export the config this way in my ormconfig.ts:

export = ORMConfig

module.exports = ORMConfig; working for me in latest version.

export = ORMConfig is the old TypeScript module format afaik.

This could be fixed in TypeORM by checking for a default property on the exported object.

Still an issue

@pleerock this is still an issue

export = ORMConfig is the old TypeScript module format afaik.

This could be fixed in TypeORM by checking for a default property on the exported object.

Agreed. This issue needs to be reopened.

The following seems to work just fine for me, maybe an update fixed this issue ?

// ormconfig.ts
import { ConnectionOptions } from 'typeorm';
export default {
  type: 'postgres',
  host: 'localhost',
  port: 5432,
  username: 'postgres',
  password: 'pass',
  database: 'filmash',
  entities: ['dist/**/*.entity{.ts,.js}'],
  synchronize: true,
} as ConnectionOptions;
// app.module.ts
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ExampleModule } from './example/example.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import connectionOptions from './ormconfig';

const IMPORTED_MODULES = [ExampleModule];

@Module({
  imports: [TypeOrmModule.forRoot(connectionOptions), ...IMPORTED_MODULES],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

is there an update on this particular issue?

I can confirm, @KillerCodeMonkey’s solution works for me 👍

Same error happen(;^ω^) But, modify config file


// ormconfig.ts
import { ConnectionOptions } from 'typeorm';

export const config: ConnectionOptions = {
 // hogehoge
};

module.exports = config;

And then, below command, no problem.


// fish. there is no '$' .
npx ts-node (npm bin)/typeorm migration:show

Same here, I just switched my ormconfig.ts file from:

export default connectionOptions;

to:

module.exports = connectionOptions;

Now it works as expected

@KillerCodeMonkey 's solution worked for me. earlier I was doing this :

import { ConnectionOptions } from “typeorm”; … … export const config_test: ConnectionOptions = { name: “default”, type: “postgres”, host:somehost, port:someport, …

I added following line at the end of the file and it started working export default config_test;

I had to set the environment variable: TYPEORM_CONNECTION to postgres

For me there was needed also to configure “typeorm” script as described in typeorm instruction

Somewhere in my code i had an extra:

TypeOrmModule.forRoot(),

Next to the main:

TypeOrmModule.forRoot({
    ...config
})

Deleting the empty one, fixed this issue

@KillerCodeMonkey works excellently, but I was using ormconfig.ts which was imported in another ts file to provide connection details (in TS.ed framework). Had to use import * as config from "./ormconfig.ts" for it to get imported without error.

Seems like, export = config exports as a module. I still don’t understand all different kind of exports yet but this worked for me.

Thanks @bertyhell, I also had an empty TypeOrmModule.forRoot(). Removing the empty one fixed it for me.

Have any of you tried deploying your apps to Heroku? using export I get unexpected token export

2020-03-25T05:07:57.946988+00:00 app[web.1]: export = ORMConfig
2020-03-25T05:07:57.946988+00:00 app[web.1]: ^^^^^^
2020-03-25T05:07:57.946988+00:00 app[web.1]: 
2020-03-25T05:07:57.946989+00:00 app[web.1]: SyntaxError: Unexpected token 'export'

Same error hapens here!! =(