tada5hi / typeorm-extension

This library provides utitlites to create & drop the database, seed the database and apply URL query parameter(s).
https://typeorm-extension.tada5hi.net
MIT License
216 stars 34 forks source link

Bug: OptionsError: The database options could not be located/loaded. #888

Open timurkhakhalev opened 8 months ago

timurkhakhalev commented 8 months ago

Versions

Reproduction

Can't load data-source when in tsconfig.json there are other options than "outDir": "dist", "rootDir": "./src", or when there are no dist folder in project I have dive into your source code and noticed that in the path variable here https://github.com/tada5hi/typeorm-extension/blob/048408c7942a90982eef491860fc390500294192/src/data-source/find/module.ts#L88 there are : ``` [ '/home/timur/dev/project', '/home/timur/dev/project/dist/database/type-orm' ] ``` I expect there /home/timur/dev/project/**src**/database/type-orm or at least /home/timur/dev/project/my-outDir-name/database/type-orm

Steps to reproduce

  1. Change "outDir" to "bin" / remove current "dist" folder / specify "rootDir" to "."
  2. tsx --env-file=.env ./node_modules/typeorm-extension/bin/cli.mjs seed:run -d src/database/type-orm/index.ts --preserveFilePaths
  3. OptionsError: The database options could not be located/loaded.

What is Expected?

What is actually happening?

tada5hi commented 6 months ago

tsx is not supported yet. Please try passing --preserveFilePaths as additional cli option.

tada5hi commented 6 months ago

at the moment typeorm-extension assumes that you execute the cli on build files. https://github.com/tada5hi/typeorm-extension/blob/02b07c3744182d7327eae9f2e4c3fee9b50c6b3f/src/utils/code-transformation/module.ts#L4

Maybe you can create a pr on how to detect tsx environment :relaxed: :v:

coler-j commented 5 months ago

I am also getting this error and --preserveFilePaths unfortunately did not resolve.

tada5hi commented 3 months ago

can you provide a reproduction repo ?

setaman commented 3 weeks ago

at the moment typeorm-extension assumes that you execute the cli on build files.

Hitting the same error in a NestJs project after switching to SWC, but that comment pointed me in the right direction. Adjusting the data source path pointing to /dist directory did the job in my case:

npx ts-node node_modules/typeorm-extension/bin/cli.cjs seed:run -d dist/seed/config/typeorm.seed.config.js