Whenever I try to import sqlite3 to test my database connection, I encounter an error. Upon inspecting the development tools, I came across the following error message:
Uncaught ReferenceError: require is not defined
at Object.path (external "path":1)
at __webpack_require__ (bootstrap:789)
at fn (bootstrap:100)
at Object../node_modules/sqlite3/lib/sqlite3.js (sqlite3.js:1)
at __webpack_require__ (bootstrap:789)
at fn (bootstrap:100)
at Object.<anonymous> (App.tsx:3)
at Object../src/App.tsx (App.tsx:22)
at __webpack_require__ (bootstrap:789)
at fn (bootstrap:100)
path @ external "path":1
__webpack_require__ @ bootstrap:789
fn @ bootstrap:100
./node_modules/sqlite3/lib/sqlite3.js @ sqlite3.js:1
__webpack_require__ @ bootstrap:789
fn @ bootstrap:100
(anonymous) @ App.tsx:3
./src/App.tsx @ App.tsx:22
__webpack_require__ @ bootstrap:789
fn @ bootstrap:100
./src/renderer.tsx @ renderer.tsx:4
__webpack_require__ @ bootstrap:789
fn @ bootstrap:100
0 @ renderer.tsx:6
__webpack_require__ @ bootstrap:789
(anonymous) @ bootstrap:856
(anonymous)
This is the code snippet I have written:
import { hot } from "react-hot-loader";
import React, { useEffect } from "react";
import sqlite3 from "sqlite3";
const App = () => {
useEffect(() => {
let db = new sqlite3.Database("./database.sqlite", (err: any) => {
if (err) {
return console.error(err.message);
}
console.log("Connected to database");
});
});
return (
<div>
<h1>Testing</h1>
<h2>sdfsdfs </h2>
</div>
);
};
export default hot(module)(App);
The technologies I am using are Electron, React, and Typescript.