MissingDriverError when type is oracle : using typeorm

12k views Asked by At

I am using typeorm in JavaScript for node and express backend like here:
https://typeorm.github.io/usage-with-javascript.html

node version v6.11.1

Dependencies from package.json:

  "@types/es6-shim": "^0.31.35",
    "@types/node": "^8.0.25",
    "async": "^2.5.0",
    "body-parser": "^1.17.2",
    "cors": "^2.8.4",
    "express": "^4.15.4",
    "oracledb": "^1.13.1",
    "reflect-metadata": "^0.1.10",
    "typeorm": "0.1.0-alpha.35"

This is the error I get:

Error:  { Error
        at new MissingDriverError (C:\Users\shodh\projects\NAPPATracking\node_modules\typeorm\error\MissingDriverError.js:22:23)
        at DriverFactory.create (C:\Users\shodh\projects\NAPPATracking\node_modules\typeorm\driver\DriverFactory.js:40:23)
        at new Connection (C:\Users\shodh\projects\NAPPATracking\node_modules\typeorm\connection\Connection.js:81:59)
        at ConnectionManager.create (C:\Users\shodh\projects\NAPPATracking\node_modules\typeorm\connection\ConnectionManager.js:56:26)
        at Object.<anonymous> (...\node_modules\typeorm\index.js:205:70)
        at step (...\node_modules\typeorm\index.js:32:23)
        at Object.next (...\node_modules\typeorm\index.js:13:53)
        at ...\node_modules\typeorm\index.js:7:71
        at __awaiter (...\node_modules\typeorm\index.js:3:12)
        at Object.createConnection (...\node_modules\typeorm\index.js:196:12)
      name: 'MissingDriverError',
      message: 'Wrong driver undefined given. Supported drivers are: "mysql", "postgres", "mssql", "oracle", "mariadb", "sqlite".' }

Here is the model:

module.exports = {
    name: "reagentsandconditionsnames",
    columns: {
        reagentnameid: {
            primary: true,
            type: "int",
            generated: true
        },
        reagentname: {
            type: "string"
        },
        datatype: {
            type: "string"
        },
        displayordernumber: {
            type: "int"
        }
    }
};

Here is the code where I am trying to access the database:

var typeorm = require("typeorm"); // import * as typeorm from "typeorm";
const oracledb = require('oracledb');
var reagentsandconditionsnames = require("./reagentsandconditionsnames"); // import {Post} from "./model/Post";
module.exports.getAllRandC = (callback) => {
  typeorm.createConnection({
      driver: {
          type: "oracle",
          host: "localhost",
          port: 1521,
          username: "uname",
          password: "pwd",
          database: "dev"
      },
      entitySchemas: [
          reagentsandconditionsnames
      ],
      autoSchemaSync: true
  }).then(function (connection) {
      console.log(connection);
      // let rncnames = await connection.entityManager.find(reagentsandconditionsnames);
      // console.log(rncnames);
      callback(null, JSON.stringify("rncnames"));
         }).catch(function(error) {
        console.log("Error: ", error);
    });
  }

What am I doing wrong?

4

There are 4 answers

2
Shodhan Manda On

looks like i was using the latest version of typeorm(0.1.0-alpha.35) when i removed that and installed the stable version(0.0.11) the errors are gone!

but now i cannot use the connection somehow, i get the following error when i do

let rncnames = await connection.entityManager.find(reagentsandconditionsnames);

at the connection

let rncnames = await connection.entityManager.find(reagentsandconditionsnames);

SyntaxError: Unexpected identifier
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)

thanks for the help!

3
Dan McGhan On

Did you do the driver install step? https://typeorm.github.io/index.html#installation

See this for details on installing node-oracledb: https://github.com/oracle/node-oracledb/blob/master/INSTALL.md

0
Agent On

I had similar issue with the help of Github I managed to solve. Please read more.

Below is my ormconfig.ts and it is inside src folder


import 'dotenv/config';
import { TypeOrmModuleOptions } from '@nestjs/typeorm';

const { DB_USERNAME, DB_PASSWORD, DB_NAME, DB_HOST } = process.env;

export const typeOrmConfig: TypeOrmModuleOptions = {
  type: 'postgres',
  username: DB_USERNAME,
  password: DB_PASSWORD,
  port: 5432,
  host: DB_HOST,
  database: DB_NAME,
  autoLoadEntities: true,
  logging: true,
  entities: ['dist/**/*.entity{ .ts,.js}'],
  migrations: ['dist/migrations/*{.ts,.js}'],
  migrationsRun: true,
  cli: {
    entitiesDir: 'src/**/*.entity{ .ts,.js}',
    migrationsDir: 'src/migrations',
  },
};

module.exports = typeOrmConfig;  # I added this line only
0
Royer Adames On

Check that you are passing the correct config values to typeorm