title: electron-packager with sqlite3 and webpack
body: <p>I'm making a small application that gets/stores data using <a href="https://www.npmjs.com/package/sqlite3" rel="nofollow noreferrer">sqlite3</a>. </p>
  
  <p>Everything was fine during development stage. But when I used <a href="https://github.com/electron-userland/electron-packager" rel="nofollow noreferrer">electron-packager</a> to pack my application, <code>sqlite3</code> doesn't work anymore. </p>
  
  <p>The console display an exception which is : <strong>Cannot find module 'sqlite3'</strong>.
  <a href="https://i.stack.imgur.com/GX52B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GX52B.png" alt="sqlite 3 exception"></a></p>
  
  <p>This is my renderer configuration:</p>
  
  <pre><code>return {
          target: 'electron-renderer',
          mode: argv.production ? 'production' : 'development',
          context: paths.root,
          devtool: !argv.production ? 'source-map' : false,
          entry: {
              'app': path.resolve(paths.app, 'app.js')
          },
          optimization: {
              runtimeChunk: false,
              splitChunks: {
                  chunks: 'all',
                  cacheGroups: {
                      default: {
                          enforce: true,
                          priority: 1
                      },
                      vendors: {
                          test: /[\\/]node_modules[\\/]/,
                          priority: 2,
                          name: 'vendors',
                          enforce: true,
                          chunks: 'async'
                      }
                  }
              }
          },
          module: {
              rules: require('./rule')(paths, argv).get()
          },
          plugins: require('./plugin')(paths, argv).get(),
          output: {
              path: paths.dist,
              filename: 'app.bundled.js'
          },
          resolve: {
              // Add `.ts` and `.tsx` as a resolvable extension.
              extensions: [".ts", ".tsx", ".js"],
              alias: {
                  // summernote: codemirror
                  'CodeMirror': 'codemirror',
              }
          },
          watch: !argv.production,
          watchOptions: {
              poll: false
          },
          externals: {
              sqlite3: 'commonjs sqlite3'
          }
      };
  </code></pre>
  
  <p>This is the file belongs to renderer process in which I include <code>sqlite3</code>:</p>
  
  <pre><code>const typeorm = require('typeorm');
  const EntitySchema = typeorm.EntitySchema;
  const path = require('path');
  const electron = require('electron');
  require('sqlite3');
  
  module.exports = (ngModule) =&gt; {
      ngModule.service('$db', (toastr) =&gt; {
  
          //#region Properties
  
          // Instance of database connection
          let dbConnection = null;
  
          //#endregion
  
          let out = {
  
              //#region Methods
                  if (dbConnection == null || forceReinitialize) {
                      // Build a absolute path to database.
                      const appPath = electron.remote.app.getAppPath();
                      const dbPath = path.join(appPath, 'assets/db/PersonalCv.db');
                      return typeorm
                          .createConnection({
                              type: "sqlite",
                              database: dbPath,
                              synchronize: false,
                              entities: [
                                  new EntitySchema(require('../models/entities/user')),
                                  new EntitySchema(require('../models/entities/user-decription')),
                                  new EntitySchema(require('../models/entities/skill-category')),
                                  new EntitySchema(require('../models/entities/skill')),
                                  new EntitySchema(require('../models/entities/personal-skill')),
                                  new EntitySchema(require('../models/entities/project')),
                                  new EntitySchema(require('../models/entities/project-skill')),
                                  new EntitySchema(require('../models/entities/project-responsibility')),
                                  new EntitySchema(require('../models/entities/responsibility'))
                              ]
                          })
                          .then((connection) =&gt; {
                              dbConnection = connection;
                              return dbConnection;
                          })
                          .catch((error) =&gt; {
                              toastr.error(error);
                              throw error;
                          });
                  }
  
                  return new Promise(resolve =&gt; {
                      resolve(dbConnection);
                  });
              },
  
              /*
              * Get repository by using name (table name)
              * */
              getRepository: (name) =&gt; {
                  return out
                      .getConnection()
                      .then((connection) =&gt; {
                          return connection.getRepository(name);
                      });
              }
  
              //#endregion
          };
  
          return out;
      });
  };
  </code></pre>
  
  <p>Here is my <a href="https://bitbucket.org/Redplane/ng-electron-structure/src" rel="nofollow noreferrer">repo</a> in case anyone needs further information.</p>
  
  <p>Can anyone help me please ?</p>
  
  <p>Thank you,</p>