Unable to make a successful connection from electron-js to sqlite3 database

127 views Asked by At

I've tried the following and also created a database

import { app, BrowserWindow, ipcMain } from 'electron';
const sqlite = require("sqlite3").verbose();
declare const MAIN_WINDOW_WEBPACK_ENTRY: any;

if (require('electron-squirrel-startup')) { // eslint-disable-line global-require
  app.quit();
}

const createWindow = (): void => {
  const mainWindow = new BrowserWindow({
    height: 600,
    width: 800,
  });

  mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY);
  mainWindow.webContents.openDevTools();
};

//connection to database file
let db = new sqlite.Database('./database.sqlite', (err: any) => {
  if(err) {
    return console.error(err.message)
  }
  console.log('Connected to database')
});

app.on('ready', createWindow);

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit();
  }
});

app.on('activate', () => {
  if (BrowserWindow.getAllWindows().length === 0) {
    createWindow();
  }
});

But I get the following error message when I run the app:

App threw an error during load
Error: node-loader:
Error: dlopen(/Users/newuser/workspace/programming/desktop/numberz/.webpack/main/fff62d64630267b2e965af6812745c92.node, 1): no suitable image found.  Did find:
    /Users/newuser/workspace/programming/desktop/numberz/.webpack/main/fff62d64630267b2e965af6812745c92.node: file too short
    /Users/newuser/workspace/programming/desktop/numberz/.webpack/main/fff62d64630267b2e965af6812745c92.node: stat() failed with errno=38
    at Object.<anonymous> (/Users/newuser/workspace/programming/desktop/numberz/.webpack/main/index.js:11824:9)
    at Object../node_modules/sqlite3/lib/binding/napi-v3-darwin-x64/node_sqlite3.node (/Users/newuser/workspace/programming/desktop/numberz/.webpack/main/index.js:11827:30)
    at __webpack_require__ (/Users/newuser/workspace/programming/desktop/numberz/.webpack/main/index.js:21:30)
    at Object../node_modules/sqlite3/lib/sqlite3-binding.js (/Users/newuser/workspace/programming/desktop/numberz/.webpack/main/index.js:11841:15)
    at __webpack_require__ (/Users/newuser/workspace/programming/desktop/numberz/.webpack/main/index.js:21:30)
    at Object../node_modules/sqlite3/lib/sqlite3.js (/Users/newuser/workspace/programming/desktop/numberz/.webpack/main/index.js:11855:15)
    at __webpack_require__ (/Users/newuser/workspace/programming/desktop/numberz/.webpack/main/index.js:21:30)
    at Object../src/index.ts (/Users/newuser/workspace/programming/desktop/numberz/.webpack/main/index.js:12576:14)
    at __webpack_require__ (/Users/newuser/workspace/programming/desktop/numberz/.webpack/main/index.js:21:30)
    at /Users/newuser/workspace/programming/desktop/numberz/.webpack/main/index.js:85:18

And when I try a method, I still get the same method above.

let db = new sqlite.Database(':memory:', (err: any) => {
  if(err) {
    return console.error(err.message)
  }
  console.log('Connected to database')
});

I've already used electron-rebuild & postnatal but still unable to make a successful connection to my database. please help

0

There are 0 answers