简体   繁体   English

在 electron 中使用 sqlite3

[英]Using sqlite3 in electron

I'm trying to build an electron app with sqlite3.Now I'm trying to use electron builder for sqlite3 but I'm getting errors even after adding postinstall dependencies :我正在尝试使用 sqlite3 构建 electron 应用程序。现在我正在尝试为 sqlite3 使用 electron 构建器,但即使在添加安装后依赖项后我也会遇到错误:

My package.json:我的 package.json:

{
  "name": "store_electron",
  "version": "1.0.0",
  "description": "trying ",
  "main": "main.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "postinstall": "install-app-deps"
  },
  "author": "armelzong@gmail.com",
  "license": "ISC",
  "dependencies": {
    "sqlite3": "^4.2.0"
  },
  "devDependencies": {
    "electron-builder": "^22.7.0",
    "electron-rebuild": "^1.11.0"
  }
}

The error I'm getting after tryied: npm run postinstall尝试后出现的错误:npm run postinstall

> install-app-deps

  • please use as subcommand: electron-builder install-app-deps
  • electron-builder  version=22.7.0
Error: Cannot compute electron version from installed node modules - none of the possible electron modules are installed.
See https://github.com/electron-userland/electron-builder/issues/3984#issuecomment-504968246
    at computeElectronVersion (C:\Users\boureima\Desktop\store_electron\node_modules\app-builder-lib\src\electron\electronVersion.ts:100:11)
    at getElectronVersion (C:\Users\boureima\Desktop\store_electron\node_modules\app-builder-lib\src\electron\electronVersion.ts:23:10)
    at async Promise.all (index 1)
    at installAppDeps (C:\Users\boureima\Desktop\store_electron\node_modules\electron-builder\src\cli\install-app-deps.ts:52:19)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! store_electron@1.0.0 postinstall: `install-app-deps`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the store_electron@1.0.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\boureima\AppData\Roaming\npm-cache\_logs\2020-06-04T10_37_40_435Z-debug.log

When using "postinstall": "electron-builder install-app-deps" : I'm getting this:使用“postinstall”时:“electron-builder install-app-deps” :我得到这个:

 ⨯ Cannot compute electron version from installed node modules - none of the possible electron modules are installed.
See https://github.com/electron-userland/electron-builder/issues/3984#issuecomment-504968246
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! store_electron@1.0.0 postinstall: ` electron-builder install-app-deps`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the store_electron@1.0.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\boureima\AppData\Roaming\npm-cache\_logs\2020-06-04T11_42_02_139Z-debug.log

Please check this post https://bitfrit.com/how-to-use-sqlite-with-electron/请查看此帖子https://bitfrit.com/how-to-use-sqlite-with-electron/

By far the easiest way to use SQLite with electron is withelectron-builder.到目前为止,将 SQLite 与 electron 一起使用的最简单方法是使用电子生成器。

First, add a postinstall step in your package.json首先,在 package.json 中添加安装后步骤

"scripts": {
   "postinstall": "electron-builder install-app-deps"
   ...
 }
"devDependencies": {
   "electron": "6.0.11",
   "electron-builder": "^21.2.0",
   ....
 }

and then install the necessary dependencies and build:然后安装必要的依赖项并构建:

npm install --save-dev electron-builder
npm install --save sqlite3
npm run postinstall

electron-builder will build the native module for your platform, with the correct name for the Electron binding; electron-builder 将为您的平台构建本机模块,并使用 Electron 绑定的正确名称; and you can then requireit in code as normal.然后你可以像往常一样在代码中要求它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM