typeorm: TypeError: Cannot read properties of undefined (reading 'type')
Issue description
Error in EntityManagerFactory using better-sqlite3 when calling AppDataSource.initialize()
Expected Behavior
DB should initialize and code should run
Actual Behavior
Error thrown in EntityManagerFactory:

BetterSqliteDriver does not have an options property (see image)
Steps to reproduce
See code listed below
My Environment
| Dependency | Version |
|---|---|
| Operating System | Windows 11 |
| Node.js version | 18.12.1 |
| Typescript version | 4.8.2 |
| TypeORM version | 0.3.12 |
| Electron | 23.1.1 |
| Angular | 15.0.0 |
Additional Context
AppDataSource:
export const AppDataSource = new DataSource({
type: "better-sqlite3",
database: "foobar2.db",
entities: [TestEntity],
synchronize: true,
logging: false,
})
Test Entity:
@Entity()
export class TestEntity{
@Column() name: string = '';
@PrimaryColumn() id: number = 0;
}
Initialization Code:
AppDataSource.initialize()
.then(() => {
console.log('db initialized!');
})
.catch((error) => console.log(error))
Relevant Database Driver(s)
- aurora-mysql
- aurora-postgres
- better-sqlite3
- cockroachdb
- cordova
- expo
- mongodb
- mysql
- nativescript
- oracle
- postgres
- react-native
- sap
- spanner
- sqlite
- sqlite-abstract
- sqljs
- sqlserver
Are you willing to resolve this issue by submitting a Pull Request?
Yes, I have the time, but I don’t know how to start. I would need guidance.
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 15
So the problem is typeorm in ‘browser’ only supports
mongodborsqljsdata source types.I found out that vite compiles typeorm drivers wrong all drives will be compiled to this:
class MongoDriver { } class MongoEntityManager { } class MongoRepository { } class PostgresDriver { } class CockroachDriver { } class SqlServerDriver { } class SapDriver { } class MysqlDriver { } class OracleDriver { } class SqliteDriver { } class BetterSqlite3Driver { }thats end in undefined variables. but i dont found out why vite is doing this.
You can get around with it, with this vite config:
This will temporale fix it for local development
+1
Same thing with ‘sqlite3’ data source type. The only difference is I am using electron-vite-vue
I had this exact exception when using this for Postgres, and the workaround that worked for me for me was to pass the driver directly into the options for to the DataSource like this:
Let me know if this workaround works for any of you.
Has anyone solved this problem yet?
mongodb doesn’ t work in vue either.
I am also facing the same problem. Has anyone solved this issue?
Do you initialize database connection everytime you introduce repositories in the preload?
any update to this, same problem with electron vite vue
me too,Have you solved it?
+1