SQLite__namespace is not a constructor

Hi Im building a Electron-Vite App and running into the following error:
TypeError: SQLite__namespace is not a constructor
at Object.<anonymous> (C:\Users\USER\OneDrive\Dokumente\Programmieren\dim_wishlist_2\out\main\index.js:26:13)
at Module._compile (node:internal/modules/cjs/loader:1271:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1326:10)
at Module.load (node:internal/modules/cjs/loader:1126:32)
at Module._load (node:internal/modules/cjs/loader:967:12)
at l._load (node:electron/js2c/asar_bundle:2:13642)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
TypeError: SQLite__namespace is not a constructor
at Object.<anonymous> (C:\Users\USER\OneDrive\Dokumente\Programmieren\dim_wishlist_2\out\main\index.js:26:13)
at Module._compile (node:internal/modules/cjs/loader:1271:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1326:10)
at Module.load (node:internal/modules/cjs/loader:1126:32)
at Module._load (node:internal/modules/cjs/loader:967:12)
at l._load (node:electron/js2c/asar_bundle:2:13642)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
I think it has something to do with the import statement of better-sqlite3
import { Database } from '@shared/databaseTypes'
import * as SQLite from 'better-sqlite3'
import { Kysely, SqliteDialect } from 'kysely'

const dialect = new SqliteDialect({
database: new SQLite('../../../resources/database.sqlite3')
})

export const db = new Kysely<Database>({
dialect
})
import { Database } from '@shared/databaseTypes'
import * as SQLite from 'better-sqlite3'
import { Kysely, SqliteDialect } from 'kysely'

const dialect = new SqliteDialect({
database: new SQLite('../../../resources/database.sqlite3')
})

export const db = new Kysely<Database>({
dialect
})
I am using TS and the error gets thrown in the built JS file so I couldn't really figure it out. If you need more details to help me pls let me know.
Solution:
This is caused by your module interop config somehow. Does it work if you use
import SQLite from 'better-sqlite3'
import SQLite from 'better-sqlite3'
...
Jump to solution
4 Replies
PunchedYou
PunchedYouOP10mo ago
out/main.js (only the important path of it):
"use strict";
const utils = require("@electron-toolkit/utils");
const electron = require("electron");
const path = require("path");
const SQLite = require("better-sqlite3");
const kysely = require("kysely");
function _interopNamespaceDefault(e) {
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
if (e) {
for (const k in e) {
if (k !== "default") {
const d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: () => e[k]
});
}
}
}
n.default = e;
return Object.freeze(n);
}
const SQLite__namespace = /* @__PURE__ */ _interopNamespaceDefault(SQLite);
const icon = path.join(__dirname, "../../resources/icon.png");
const dialect = new kysely.SqliteDialect({
database: new SQLite__namespace("../../../resources/database.sqlite3")
});
const db = new kysely.Kysely({
dialect
});
[...]
"use strict";
const utils = require("@electron-toolkit/utils");
const electron = require("electron");
const path = require("path");
const SQLite = require("better-sqlite3");
const kysely = require("kysely");
function _interopNamespaceDefault(e) {
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
if (e) {
for (const k in e) {
if (k !== "default") {
const d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: () => e[k]
});
}
}
}
n.default = e;
return Object.freeze(n);
}
const SQLite__namespace = /* @__PURE__ */ _interopNamespaceDefault(SQLite);
const icon = path.join(__dirname, "../../resources/icon.png");
const dialect = new kysely.SqliteDialect({
database: new SQLite__namespace("../../../resources/database.sqlite3")
});
const db = new kysely.Kysely({
dialect
});
[...]
Error gets thrown in line 26: database: new SQLite__namespace("../../../resources/database.sqlite3")
Solution
koskimas
koskimas10mo ago
This is caused by your module interop config somehow. Does it work if you use
import SQLite from 'better-sqlite3'
import SQLite from 'better-sqlite3'
PunchedYou
PunchedYouOP10mo ago
Omg thanks I somehow tried everything except that like importing Database, ...
PunchedYou
PunchedYouOP10mo ago
Then the getting started guide prop needs an update?
No description
Want results from more Discord servers?
Add your server