How to make SQLite to work with Angular 4+, Electr

2019-03-22 03:25发布

I'm trying to build one small desktop app using:

  • Angular 4+
  • NodeJS
  • Electron
  • SQLite3

NodeJS will be used for scanning local user hdd and inserting specific files that are found into SQLite3 database.

I checked dozens of documentation and suggestions. Most of them suggest to use NodeJS express framework and make layer between Angular 4+ -> Express -> SQLite3.

I want to avoid using express framework because it is going to be desktop app and it is not needed at all.

What I tried and what I did:

I installed:

   "sqlite3": "^3.1.9",
   "node-pre-gyp": "^0.6.36",

as dependencies in my project.

Than I have read if you want to use native nodejs library you should run electron rebuild. So I installed also electron rebuild:

"electron-rebuild": "^1.6.0"

as a devDependencies and run it with following command:

./node_modules/.bin/electron-rebuild

Rebuild sqlite3 successfully finished.

Than I run electron application and I get following error:

/~/node-pre-gyp/lib/node-pre-gyp.js
Module build failed: Error: ENOENT: no such file or directory, open '/home/haris/development/walter/angular-electron-starter/node_modules/node-pre-gyp/lib/node-pre-gyp.js'
    at Error (native)
 @ ./~/sqlite3/lib/sqlite3.js 1:13-36
 @ ./src/app/home/home.component.ts
 @ ./src/app/home/index.ts
 @ ./src/app/app.module.ts
 @ ./src/app/index.ts
 @ ./src/main.browser.ts
 @ multi (webpack)-dev-server/client?http://localhost:3000 ./src/main.browser.ts

I stuck here. I tried many more things like:

1. Removing node_modules
2. npm install --build-from-source

but still I'm getting the same error.

Any suggestion or help will be very appreciated.

2条回答
走好不送
2楼-- · 2019-03-22 03:42

I've just published a sample project which shows how to build a desktop app using Electron, Angular4 and Sqlite3. You can clone it here

Note I've node-gyp globally installed.

Hope it helps

查看更多
ゆ 、 Hurt°
3楼-- · 2019-03-22 03:43

For what it might be worth to others. I had followed the steps from @leota (very good thank you BTW!).

My problem is I had Python 2.7 x64 version, and I think it needed the 32 bit version.. as I installed the standard version, my rebuild process worked fine!

查看更多
登录 后发表回答