如何解决sqlite3_1.default.database 不是构造函数
我通过 yarn 安装在我的 Electron-React-Typescript-Webpack 应用程序 sqlite3
中:yarn add sqlite3@latest
并使用 yarn electron-rebuild -f -w sqlite3
在 webpack.config.js
中,我输入了:
const webpack = require('webpack');
externals: [
{
'sqlite3': sqlite3,}
],
如果在 main.ts
中,我输入:
import sqlite3 from 'sqlite3';
let db = new sqlite3.Database(
path.join(app.getPath('userData'),'/infopiecesleveldb'),(err) => {
if (err) {
return console.error(err.message);
}
console.log('Connected to the in-memory sqlite database.');
});
我收到此错误:sqlite3_1.default.database is not a constructor
(node:2679) UnhandledPromiseRejectionWarning: TypeError: sqlite3_1.default.database is not
a constructor
at App.<anonymous> (/home/marco/webMatters/electronMatters/Raphy-Template/dist/main
/main.js:60:32)
at App.emit (events.js:315:20)
(Use `electron --trace-warnings ...` to show where the warning was created)
(node:2679) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error
originated either by throwing inside of an async function without a catch block,or by
rejecting a promise which was not handled with .catch(). To terminate the node process on
unhandled promise rejection,use the CLI flag `--unhandled-rejections=strict` (see
https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:2679) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In
the future,promise rejections that are not handled will terminate the Node.js process with
a non-zero exit code.
mainWindow loaded
关于如何解决它的任何想法?
解决方法
与
import sqlite3 from 'sqlite3';
//let db = new sqlite3.Database(':memory:',(err) => {
let db = new sqlite3.Database(
path.join(app.getPath('userData'),'/infopiecessql3db'),(err) => {
if (err) {
return console.error(err.message);
}
console.log('Connected to the in-memory SQlite database.');
});
db.close();
现在我收到这条消息Connected to the in-memory SQlite database
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。