electron - sqlite3_1.default.database 不是构造函数
问题描述
sqlite3
我通过纱线安装在我的 Electron-React-Typescript-Webpack 应用程序中: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
推荐阅读
- docker - Docker-compose:挂载非 root 用户可用的 tmpfs
- sql - SQL根据类别从表中选择最新日期
- java - com.couchbase.client.java.error.MixedAuthenticationException 与 Couchbase 和 Spring Boot
- atom-editor - 为 Atom 编辑器添加后缀以正确显示代码
- jakarta-ee - Wildfly Artemis ActiveMQ 查找失败
- angular - 一旦父级在 forEach 中使用 observables 完成,角度触发子函数
- c++ - c++ 参考成员:好的做法?
- android - 安装 'cordova-plugin-firebase' 失败:CordovaError: Uh oh
- linux - 如何为 macOS 应用程序包和 linux 可执行文件签署数字签名
- sql-server - Cast char '-' 减去为什么它在 sql server 2016 中变成零“0”?