错误:在任何 orm 配置文件中均未找到连接选项

ash*_*raz 10 oracle node.js typescript typeorm

我想用 typeorm 连接到 oracle

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));
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

ormconfig.json是在./Myproject/ormconfig.json但说错误:错误:在任何 orm 配置文件中找不到连接选项。

通过这些设置,我已经使用 oracledb 连接到数据库。

请帮我

更新

我用这个生成项目typeorm init --name MyProject --database oracle。这是 typeorm 的默认结构。

Ntw*_*ste 9

您好,我有一天遇到了同样的错误,但我必须明确显示配置文件的路径这是我当前的typeorm package.json脚本命令

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

我把它改为

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

不是我如何显式设置我正在使用的配置文件的路径,无论您使用哪个扩展名.js.ts或者.json

这是我的配置文件的示例

// 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' },
};


Run Code Online (Sandbox Code Playgroud)

希望它会有所帮助


spi*_* 王建 2

从您发布的图片来看,您放错了ormconfig.json./src 目录,该路径可能是your_project/src/ormconfig.json。请将其移动到项目的根目录(路径:)your_project/ormconfig.json即可解决!