typeorm-extension: Bug: OptionsError: The database options could not be located/loaded.
Versions
- Node: v18.17.1
- OS: MacOS Sonoma 14.2
Reproduction
When executing db:create/drop, it gives the following error:
OptionsError: The database options could not be located/loaded.
at OptionsError.notFound
Additional Details
DataSource file:
config();
const configService = new ConfigService();
export const dataSourceOptions: DataSourceOptions & SeederOptions = {
type: 'mysql',
host: configService.getOrThrow('DB_HOST'),
port: configService.getOrThrow('DB_PORT'),
database: configService.getOrThrow('DB_DATABASE'),
username: configService.getOrThrow('DB_USERNAME'),
password: configService.getOrThrow('DB_PASSWORD'),
entities: ['dist/**/*.entity{.ts,.js}'],
migrations: ['dist/db/migrations/*.js'],
migrationsTableName: 'migrations',
};
export default new DataSource(dataSourceOptions);
Steps to reproduce
npm run db:create
What is Expected?
To locate the datasource file correctly
What is actually happening?
Its throwing the following error:
OptionsError: The database options could not be located/loaded. at OptionsError.notFound
It runs when i change the following in the “findDataSource” function:
if (info) {
let fileExports = await locter.load(info);
if (isPromise(fileExports)) {
fileExports = await fileExports;
}
if (typeorm.InstanceChecker.isDataSource(fileExports)) {
return fileExports;
}
const defaultExport = locter.getModuleExport(fileExports);
if (isPromise(defaultExport.value)) {
defaultExport.value = await defaultExport.value;
}
// Added .default to the defaultExport.value
if (defaultExport && typeorm.InstanceChecker.isDataSource(defaultExport.value.default)) {
return defaultExport.value.default;
}
if (locter.isObject(fileExports)) {
const keys = Object.keys(fileExports);
for(let j = 0; j < keys.length; j++){
let value = fileExports[keys[j]];
if (isPromise(value)) {
value = await value;
}
if (typeorm.InstanceChecker.isDataSource(value)) {
return value;
}
}
}
}
About this issue
- Original URL
- State: closed
- Created 5 months ago
- Comments: 16 (7 by maintainers)
I can confirm that
v3.4.0has fixed it for me.Issue should be solved with
v3.4.0.https://github.com/testing-library/user-event/issues/813 https://stackoverflow.com/questions/62717394/export-default-class-exports-double-nested-default
It would be great if you could have a look at 3.4.0-beta.1 and check if the problem persists. In theory typeorm-extension should handle esm and cjs as well. You have an esm project right ? Do you execute the compiled js file or do you use ts-node ?