electron-rebuild
安装electron-rebuild
cnpm install electron-rebuild --save-dev
electron支持原生模块
https://www.electronjs.org/docs/tutorial/using-native-node-modules
为 Electron 安装并重新编译模块
您可以像其他 Node 项目一样安装模块,然后用 electron-rebuild 包重建这些模块以适配 Electron 。 这个包可以自动识别当前 Electron 版本,为你的应用自动完成下载 headers、重新编译原生模块等步骤。
例如,想要通过命令行下载 electron-rebuild 并重新编译:
npm install --save-dev electron-rebuild
# 每次运行"npm install"后,也运行这条命令
./node_modules/.bin/electron-rebuild
# 在windows下如果上述命令遇到了问题,尝试这个:
.
ode_modules.binelectron-rebuild.cmd
SQLite和Knex.js
安装 SQLite
cnpm install sqlite3
运行出现问题:electron与node_sqlite3版本不一致
Error: The module '\?E:KzoneCodeLibelectronelectron-actionClipmaster-charp12-SQLite
ode_modules\_sqlite3@4.2.0@sqlite3libindingelectron-v9.0-win32-x64
ode_sqlite3.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 72. This version of Node.js requires
NODE_MODULE_VERSION 80. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
at process.func [as dlopen] (electron/js2c/asar.js:140:31)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1034:18)
at Object.func [as .node] (electron/js2c/asar.js:140:31)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Module._load (internal/modules/cjs/loader.js:727:14)
at Function.Module._load (electron/js2c/asar.js:738:28)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (E:KzoneCodeLibelectronelectron-actionClipmaster-charp12-SQLite
ode_modules\_sqlite3@4.2.0@sqlite3libsqlite3-binding.js:4:15)
at Module._compile (internal/modules/cjs/loader.js:967:30)
npm install sqlite3 --build-from-source --runtime=electron --target=9.0.3 --dist-url=https://atom.io/download/electron