Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: No connection options were found in any orm configuration files

I want connect to oracle with typeorm

createConnection().then(async connection => {
    const app = express();
    const userRepository = getRepository(User);
    const users = await userRepository.find();
    console.log(users);   
    app.listen(3000);
}).catch(error => console.log("xxx",error));

enter image description here

ormconfig.json is in ./Myproject/ormconfig.json but say error :Error: No connection options were found in any orm configuration files.

With these settings , I was already connected to the database with the oracledb.

Please help me

UPDATE

I generate project with this typeorm init --name MyProject --database oracle. This is typeorm default structure.

like image 640
ashkufaraz Avatar asked Sep 22 '20 14:09

ashkufaraz


3 Answers

Hello I had the same error for one day, but I had to explicitly show the path of the config file This was my current typeorm package.json script command

"typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js"

i changed it to

"typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js --config src/config/postgres.config.ts"

not how I explicitly set the path of the config file that I am using, no matter which extension you are using, either .js, .ts, or .json

here is the example of my config file

// postgres.config.ts

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

export const pgConfig: TypeOrmModuleOptions = {
  type: 'postgres',
  host: process.env.POSTGRES_HOST,
  port: parseInt(<string>process.env.POSTGRES_PORT),
  username: process.env.POSTGRES_USER,
  password: process.env.POSTGRES_PASSWORD,
  database: process.env.POSTGRES_DATABASE,
  entities: ['dist/src/modules/**/entities/*.entity.js'],
  synchronize: true,
  migrations: ['dist/src/db/migrations.js'],
  cli: { migrationsDir: 'src/db/migrations' },
};


Hope it gonna help

like image 141
Ntwari Clarance Liberiste Avatar answered Oct 20 '22 00:10

Ntwari Clarance Liberiste


From the picture you posted, you misplaced the ormconfig.json in ./src directory which path maybe your_project/src/ormconfig.json.Please move it to root directory of project(path: your_project/ormconfig.json) will work out!

like image 2
spike 王建 Avatar answered Oct 19 '22 23:10

spike 王建


You can try use the following instead

npx typeorm migration:create -n migrationName
like image 2
Ian Samz Avatar answered Oct 19 '22 22:10

Ian Samz