使用Angular和Knex创建电子项目

时间:2018-09-28 09:17:29

标签: angular electron knex.js

我有问题。

我正在尝试使用ElectronAngular创建一个Knex并使用sqlite3进行存储。

我使用了angular-electron,然后尝试将一个服务添加到angular来管理数据库。

我尝试遵循Knex文档,但是每次尝试运行它时,都会出现此错误:

Module not found: Error: Can't resolve 'aws-sdk' in 'D:\Projects\IonicProjects\testing\angular-electron\node_modules\node-pre-gyp\lib'
ERROR in ./node_modules/knex/lib/dialects/mssql/index.js
Module not found: Error: Can't resolve 'mssql' in 'D:\Projects\IonicProjects\testing\angular-electron\node_modules\knex\lib\dialects\mssql'
ERROR in ./node_modules/knex/lib/dialects/mssql/index.js
Module not found: Error: Can't resolve 'mssql/lib/base' in 'D:\Projects\IonicProjects\testing\angular-electron\node_modules\knex\lib\dialects\mssql'
ERROR in ./node_modules/knex/lib/dialects/mssql/index.js
Module not found: Error: Can't resolve 'mssql/package.json' in 'D:\Projects\IonicProjects\testing\angular-electron\node_modules\knex\lib\dialects\mssql'
ERROR in ./node_modules/knex/lib/dialects/mysql/index.js
Module not found: Error: Can't resolve 'mysql' in 'D:\Projects\IonicProjects\testing\angular-electron\node_modules\knex\lib\dialects\mysql'
ERROR in ./node_modules/knex/lib/dialects/mysql2/index.js
Module not found: Error: Can't resolve 'mysql2' in 'D:\Projects\IonicProjects\testing\angular-electron\node_modules\knex\lib\dialects\mysql2'
ERROR in ./node_modules/knex/lib/dialects/oracle/index.js
Module not found: Error: Can't resolve 'oracle' in 'D:\Projects\IonicProjects\testing\angular-electron\node_modules\knex\lib\dialects\oracle'
ERROR in ./node_modules/knex/lib/dialects/oracledb/index.js
Module not found: Error: Can't resolve 'oracledb' in 'D:\Projects\IonicProjects\testing\angular-electron\node_modules\knex\lib\dialects\oracledb'
ERROR in ./node_modules/knex/lib/dialects/postgres/index.js
Module not found: Error: Can't resolve 'pg' in 'D:\Projects\IonicProjects\testing\angular-electron\node_modules\knex\lib\dialects\postgres'
ERROR in ./node_modules/knex/lib/dialects/redshift/index.js
Module not found: Error: Can't resolve 'pg' in 'D:\Projects\IonicProjects\testing\angular-electron\node_modules\knex\lib\dialects\redshift'
ERROR in ./node_modules/knex/lib/dialects/postgres/index.js
Module not found: Error: Can't resolve 'pg-query-stream' in 'D:\Projects\IonicProjects\testing\angular-electron\node_modules\knex\lib\dialects\postgres'
ERROR in ./node_modules/knex/lib/dialects/mssql/index.js
Module not found: Error: Can't resolve 'tedious' in 'D:\Projects\IonicProjects\testing\angular-electron\node_modules\knex\lib\dialects\mssql'

有人能指出我正确的方向吗?我没有用Angular为UI创建Electron应用程序的问题。换句话说,一个使用Electron打包为桌面应用程序的Angular应用程序,但是我需要一种存储解决方案,并且想使用Sqlite3,但是还没有找到诸如此类的项目的任何预制模板,并希望获得您的帮助。

2 个答案:

答案 0 :(得分:0)

我想您没有安装这些库。那些错误是由于未安装的数据库驱动程序软件包引起的。 Knex不会自动安装它们,您不需要全部。

如果有与此相关的Webpack配置,则您应该能够忽略其中的大多数库,而仅采用所需的驱动程序。

但是,您可能只能在电子应用程序的主线程中运行knex库,因此也许您试图将其打包为有角度的,这可能根本无法工作。

答案 1 :(得分:0)

尝试将其添加到您的webpack-config

var fs = require("fs");
const nodeModules = {};
fs.readdirSync("node_modules")
  .filter(x => {
      return [".bin"].indexOf(x) === -1;
})
.forEach(mod => {
        nodeModules[mod] = `commonjs ${mod}`;
    });

module.exports = {
    // ommitted for brevity
    externals: [nodeModules],
}