Typeorm not working in my electron app (this.driver connect is not a function)

Viewed 1105

When I try to use the typeorm libary the connection internaly fails because it cannot resolve the correct driver whith an connect() method.

Anyone has an Idea why this is? It seems like an Issue of me being in browser not having direct access to node.js sqlite driver, but according to typeorm docs this should work.

So I have no Idea at the moment why this won't work.

//App.tsx

const App = () => {
  useEffect(() => {
    InitDatabase.initDatabase();
    return () => {
      InitDatabase.close();
    };
  }, []);
  ...
}
//InitDatabase.service.ts

...
public static async initDatabase() {
    await this.close();
    this.database =
      await createConnection({
        name: "default",
        type: "sqlite",
        database: "database.sqlite",
        entities: [TimetrackingItem],
        logging: true,
      });
    return this.database;
  }
...
//react.webpack.config.js

const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const FilterWarningsPlugin = require("webpack-filter-warnings-plugin");

const rootPath = path.resolve(
  __dirname,
  "..",
);

module.exports = {
  resolve: {
    extensions: [".tsx", ".ts", ".js"],
    mainFields: [
      "main",
      "module",
      "browser",
    ],
  },
  entry: path.resolve(
    rootPath,
    "src",
    "App.tsx",
  ),
  target: "electron-renderer",
  devtool: "source-map",
  module: {
    rules: [
      {
        test: /\.(js|ts|tsx)$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
        },
      },
    ],
  },
  devServer: {
    contentBase: path.join(
      rootPath,
      "dist/renderer",
    ),
    historyApiFallback: true,
    compress: true,
    hot: true,
    host: "0.0.0.0",
    port: 4000,
    publicPath: "/",
  },
  output: {
    path: path.resolve(
      rootPath,
      "dist/renderer",
    ),
    filename: "js/[name].js",
    publicPath: "./",
  },
  plugins: [
    new HtmlWebpackPlugin(),
    new FilterWarningsPlugin({
      exclude: [
        /mongodb/,
        /mssql/,
        /mysql/,
        /mysql2/,
        /oracledb/,
        /pg/,
        /pg-native/,
        /pg-query-stream/,
        /react-native-sqlite-storage/,
        /redis/,
        /sql.js/,
        /typeorm-aurora-data-api-driver/,
      ],
    }),
  ],
  externals: {
    sqlite3: "commonjs sqlite3",
  },
};

0 Answers
Related