admin管理员组

文章数量:1127896

I am working on an Electron + React + Vite project where I want to use TypeORM to manage database access. The idea is to use an SQLite database so that everything runs on the same device, Once the Data Source is configured.

import { DataSource } from "typeorm"

export const LocalAppDataSource = new DataSource({
    type: "sqlite",
    database: "./db/database.sql",
    synchronize: true,
    logging: true,
    entities: [],
    migrations: [],
    subscribers: [],
})

When I try to initialize it in the electron/main.ts file:

app.on('activate', () => {
  // On OS X it's common to re-create a window in the app when the
  // dock icon is clicked and there are no other windows open.
  if (BrowserWindow.getAllWindows().length === 0) {

    LocalAppDataSource.initialize()
    .then(() => {
      console.log('Conexión a SQLite establecida');
    })
    .catch((err) => {
        console.error("Error during Data Source initialization", err)
    })

    createWindow()
    
  }
})

The application shows this error:

I tried reinstalling TypeORM, but it keeps malfunctioning. I also tried performing the initialization in the same data-source file, but it still doesn’t work.

I also tried installing the google-cloud/spanner dependency, but it requires the mongodb dependency, and so on with all the available types.

My package.json is as follows:

{
  "name": "gestionbarapp",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "tsc && vite build && electron-builder",
    "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
    "preview": "vite preview",
    "start": "electorn --trace-warnings",
    "typeorm": "typeorm-ts-node-commonjs"
  },
  "dependencies": {
    "better-sqlite3": "^9.6.0",
    "lucide-react": "^0.468.0",
    "pg": "^8.13.1",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-feather": "^2.0.10",
    "react-icons": "^5.4.0",
    "react-router-dom": "^7.0.2",
    "reflect-metadata": "^0.2.2",
    "sqlite": "^5.1.1",
    "sqlite3": "^5.1.7",
    "typeorm": "^0.3.20"
  },
  "devDependencies": {
    "@rollup/plugin-commonjs": "^28.0.2",
    "@types/better-sqlite3": "^7.6.12",
    "@types/node": "^22.10.2",
    "@types/react": "^18.2.64",
    "@types/react-dom": "^18.2.21",
    "@typescript-eslint/eslint-plugin": "^7.1.1",
    "@typescript-eslint/parser": "^7.1.1",
    "@vitejs/plugin-react": "^4.2.1",
    "electron": "^30.5.1",
    "electron-builder": "^24.13.3",
    "eslint": "^8.57.0",
    "eslint-plugin-react-hooks": "^4.6.0",
    "eslint-plugin-react-refresh": "^0.4.5",
    "ts-node": "^10.9.2",
    "typescript": "^5.7.2",
    "vite": "^5.1.6",
    "vite-plugin-electron": "^0.28.8",
    "vite-plugin-electron-renderer": "^0.14.5",
    "vite-tsconfig-paths": "^5.1.4"
  },
  "main": "dist-electron/main.js"
}

本文标签: reactjsInitialization of TypeORM requests all types of drivers for different databasesStack Overflow