typeorm / typeorm

ORM for TypeScript and JavaScript. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.
http://typeorm.io
MIT License
34.42k stars 6.33k forks source link

couldn't create a connection with ormconfig.ts #7141

Closed ginachoi closed 3 years ago

ginachoi commented 3 years ago

Issue Description

I am developing an app using Typescripts and NodeJS. We used Sequelize before but I decided to give it try with TypeORM since it's a lots similar with Hibernate. I started the project with ormconfig.json but since we can't reference environment variables I switched to ormconfig.ts. I know TypeORM supports ormconfig.js but since our app is TypeScript based ormconfig.ts makes more sense to us. But I was getting Following error message.

No connection options were found in any orm configuration files

And here is my ormconfig.ts file

import { ConnectionOptions } from "typeorm";

export const config: ConnectionOptions = {
  type: "postgres",
  url: "postgresql://test:test@localhost:5432/test",
  connectTimeoutMS: 5000,
  migrationsRun: true,
  synchronize: false,
  maxQueryExecutionTime: 5000,
  logging: ["query", "error", "schema"],
  logger: "advanced-console",
  extra: {
    max: 15,
    min: 5,
    idleTimeoutMillis: 30000,
  },
  seeds: ["dist/**/database/seeds/*.js"],
  factories: ["src/factories/**/*{.ts,.js}"],
  entities: ["dist/**/entities/*{.ts,.js}"],
  migrations: ["dist/**/migration/**/*{.ts,.js}"],
  subscribers: ["src/subscriber/**/*{.ts,.js}"],
  cli: {
    entitiesDir: "src/entity",
    migrationsDir: "src/database/migration",
    subscribersDir: "src/subscriber",
  },
};

module.exports = config;

Expected Behavior

According to TypeROM wiki page, it clearly mentioned that ormconfig.ts file is supported.

From the other ormconfig.[format] files, in this order: [js, ts, json, yml, yaml, xml].

Actual Behavior

When I use ormconfig.js I am getting following error message. No connection options were found in any orm configuration files

Steps to Reproduce

  1. use ormconfig.ts to configure TypeORM.
  2. Start the app and try to connect to database

My Environment

Dependency Version
Operating System
Node.js version v12.18.1
Typescript version v4.0.5
TypeORM version v0.2.29

Additional Context

Relevant Database Driver(s)

Are you willing to resolve this issue by submitting a Pull Request?

angelxmoreno commented 3 years ago

Please specify the location of your config file. Also please note that on https://typeorm.netlify.app/#/using-ormconfig/using-ormconfigjs it states Create ormconfig.* in the project root (near package.json)

I am currently looking for a way to point the config file so that i can have it inside of src/

imnotjames commented 3 years ago

I can't replicate this issue.


When opening an issue, people will be better able to provide help if you provide code that they can easily understand and use to reproduce the problem. This boils down to ensuring your code that reproduces the problem follows the following guidelines:

Minimal

The more code there is to go through, the less likely people can find your problem. Streamline your example in one of two ways:

  1. Restart from scratch. Create a new program, adding in only what is needed to see the problem. Use simple, descriptive names for functions and variables – don’t copy the names you’re using in your existing code.
  2. Divide and conquer. If you’re not sure what the source of the problem is, start removing code a bit at a time until the problem disappears – then add the last part back.

Don't sacrifice clarity for brevity when creating a minimal example. Use consistent naming and indentation, and include code comments if needed. Use your code editor’s shortcut for formatting code.

Don't include any passwords or credentials that must be kept secret.

Complete

Make sure all information necessary to reproduce the problem is included in the issue itself.

If the problem requires some code as well as some XML-based configuration, include code for both. The problem might not be in the code that you think it is in.

Use individual code blocks for each file or snippet you include. Provide a description for the purpose of each block.

DO NOT use images of code. Copy the actual text from your code editor, paste it into the issus, then format it as code. This helps others more easily read and test your code.

Reproducible

To help you solve your problem, others will need to verify that it exists.

Describe the problem. "It doesn't work" isn't descriptive enough to help people understand your problem. Instead, tell other readers what the expected behavior should be. Tell other readers what the exact wording of the error message is, and which line of code is producing it. Use a brief but descriptive summary of your problem as the title of your question.

Eliminate any issues that aren't relevant to the problem. If your question isn’t about a compiler error, ensure that there are no compile-time errors.

Double-check that your example reproduces the problem! If you inadvertently fixed the problem while composing the example but didn't test it again, you'd want to know that before asking someone else to help.