typeorm: Sqlite driver in Webpack/Electron on 0.2.28: (TypeError): this.driver.connect is not a function

Issue type:

[x] bug report [ ] feature request [ ] documentation issue

Database system/driver:

[ ] cordova [ ] mongodb [ ] mssql [ ] mysql / mariadb [ ] oracle [ ] postgres [ ] cockroachdb [x] sqlite [ ] sqljs [ ] react-native [ ] expo

TypeORM version:

0.2.28

Steps to reproduce or a small repository showing the problem:

Clone the reproduction repo at https://github.com/jjhbw/typeorm-webpack-electron-repro See simple instructions on how to trigger the error in the repo’s README. Note that the invocation of createConnection resides in src/App.js.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (15 by maintainers)

Commits related to this issue

Most upvoted comments

@dominicdesu @jjhbw First sorry for my english kk, i am creating an application using vue and electron and encountered the same problem, i solved this with folow config in webpack

module.exports = {
  // ...
  externals: {
    typeorm: 'commonjs typeorm',
    sqlite3: 'commonjs sqlite3'
  }
};

My solution was this and electron builder config, for you this solution should solve. The original webpack documentation: https://webpack.js.org/configuration/externals/#externals The issue where encountered the solution for my problem: https://github.com/nklayman/vue-cli-plugin-electron-builder/issues/699

The sqlite driver uses https://www.npmjs.com/package/sqlite which is a binary driver that is only available for node. It does not work from a browser as it’s a C library.

Yes, i’m aware. Hence my snark regarding the hypothetical devs who try to use it in a browser context. 😉

If we do not do this then webpack build targeting browsers with mainFields will fail to build entirely, as webpack tries to resolve this even if the file is not imported.

Ah, that makes sense. Did not think of that case. In light of that, I’d say you’re right not to accommodate this in TypeORM… I guess the only way is to get Webpack to fix the mainFields issue instead.

Thanks for the time you spend on this library! Much appreciated.