Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export ormconfig #5003

Closed
TrejGun opened this issue Oct 31, 2019 · 8 comments · Fixed by #6853
Closed

export ormconfig #5003

TrejGun opened this issue Oct 31, 2019 · 8 comments · Fixed by #6853

Comments

@TrejGun
Copy link

TrejGun commented Oct 31, 2019

I want to reopen issue #4068

in short I ask to move from old ts syntax

export = ORMConfig

to new

export default ORMConfig
@chanmathew
Copy link

Ran into this issue as well and had to solve it by using the old ts syntax to export

@TrejGun
Copy link
Author

TrejGun commented Dec 20, 2019

can you please eleborate why it is designed this way? what benefits it gives?

@Kononnable
Copy link
Contributor

This feature was designed long time ago when default exports was not popular or even not possible yet.

@artoodeeto

This comment has been minimized.

@TrejGun
Copy link
Author

TrejGun commented Mar 5, 2020

babel 7.8.6 stopped to support this syntax and throws error

Babel compilation error SyntaxError: ~/ormconfig.ts: `export =` is not supported by @babel/plugin-transform-typescript
Please consider using `export <value>;`.

@imnotjames imnotjames self-assigned this Oct 4, 2020
imnotjames added a commit to imnotjames/typeorm that referenced this issue Oct 5, 2020
imnotjames added a commit to imnotjames/typeorm that referenced this issue Oct 5, 2020
pleerock pushed a commit that referenced this issue Oct 5, 2020
@napisani
Copy link

I was still having some problems with the mix between CommonJS (used by the CLI) and ESNext (used by the latest version of NestJS) here is what i did to get around the problem, incase it helps someone having the same problem:

ormconfig.ts

export default {
  type: 'mariadb',
  host: data.DATABASE_HOST,
  port: data.DATABASE_PORT,
  username: data.DATABASE_USER,
  password: data.DATABASE_PASS,
  database: data.DATABASE_SCHEMA,
//... etc
  }
};

in ormconfig_cli.ts

import ormconfig from './ormconfig';

// the TypeORM cli requires the modules to use CommonJS
// while the app  requires ESNext
// - this file takes the ESNext module and exports it in CommonJS format
export = ormconfig

in package.json

...
    "api:typeorm": "ts-node  -P apps/api/tsconfig.json  -O '{\"module\":\"commonjs\"}' -r tsconfig-paths/register ./node_modules/typeorm/cli.js --config apps/api/src/app/ormconfig_cli.ts",
    "api:typeorm:migrate": "npm run api:typeorm migration:generate -- -n migrations",
    "api:typeorm:run": "npm run api:typeorm migration:run"
...

in app module:

import ormconfig from './ormconfig';



@imnotjames
Copy link
Contributor

imnotjames commented Oct 15, 2020

This change should be live in 0.2.29 - which will be released in a few days. At that point you shouldn't need that hack 🙌 But good to know the workaround!

@TrejGun
Copy link
Author

TrejGun commented Nov 3, 2020

fixed, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants