-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
Bug: OptionsError: The database options could not be located/loaded. #845
Comments
@alancghizzi Do you have a cjs or esm project? Do you use Typescript for compilation? |
I am having the same issue. I am trying to use typeorm-extension npm package for seed data into the table. Please suggest me. how i can archive this? Details: Node JS : Code : import { DataSource, DataSourceOptions } from "typeorm";
import * as dotenv from "dotenv";
import { TokenEntity } from "./entities/token.entity.js";
dotenv.config();
const getConfig = (env: string) => {
return {
type: process.env[`DB_DIALECT_${env}`],
host: process.env[`DB_HOST_${env}`],
port: Number(process.env[`DB_PORT_${env}`]),
username: process.env[`DB_USER_${env}`],
password: process.env[`DB_PASS_${env}`],
database: process.env[`DB_NAME_${env}`],
synchronize: false,
logging: false,
entities: [
'src/migrator/entities/*.entity.ts'
],
subscribers: [],
migrations: [
'src/migrator/migrations/*.ts'
],
seeds: [
'src/migrator/seeds/*.ts'
],
migrationsTableName: 'migrations',
};
};
const env = process.env.NODE_ENV || 'development';
export const AppDataSource = new DataSource(getConfig(env.toUpperCase()) as DataSourceOptions);
export const tokenListRepository = AppDataSource.getRepository(TokenEntity); Scripts in package.json
On run : ERROR : OptionsError: The database options could not be located/loaded. Please suggest me with solutions. |
@lav-panchal mhhh, from your code snippet, I deduced that you are running an esm project. I tried to replicate your problem. After you have run What is your tsconfig content ? |
@tada5hi the main diff i noticed is that i dont import "reflect-metadata" in my datasource, could that be an issue? ps: its cjs and yes, i use ts for compilation This is my datasource file (just replaced the import names to make it clearer):
my tsconfig:
|
tsconfig.json
|
@tada5hi Now getting this error:
|
where is your data source file located ? |
./src/migrator/index.ts |
what have you changed ? |
script : |
can you please check version |
Hi @tada5hi , I haven't tested version 3.4.0-beta.1 but I want to add some information here, which might help. We faced a similar issue recently when running typeorm-extension cli commands and trying to provide the datasource. So we were getting a weird error that 'TypeORMError: No connection options were found in any orm configuration files.' and this error was happening with typeorm-extension. After much investigation we found out that typeorm can see the datasource when we do:
And typeorm-extension can see the datasource when we do:
So we ended up providing one datasource for typeorm and another one for typeorm-extension, because funny thing is that typeorm doesn't work with module.exports, it throws :
I hope this helps the situation. We suspect that it has to do with how the dataSource is nested when we use es module, and findDataSource needs to adjust a little bit to handle this case. When we use commonjs module there is no wrapper object around it so it can read the dataSource properly. |
It would be great if you could have a look at 3.4.0-beta.1 and check if the problem persists. |
Ahhh I checked and it seems the problem persists with 3.4.0-beta.1, at least the one I have. The project that I have is commonjs. And when I run my script (I use the compiled js file) I get this error:
Also please note that in order to overcome this issue, I went and manually adjusted the package.json of typeorm-extension specifically the exports section and added this entry also :
|
Issue should be solved with testing-library/user-event#813 |
I can confirm that |
Versions
Reproduction
When executing db:create/drop, it gives the following error:
Additional Details
DataSource file:
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:
The text was updated successfully, but these errors were encountered: