Using NodeJS plugins in Electron(在 Electron 中使用 NodeJS 插件)
问题描述
我是 Electron (Atom-shell) 的新手,我正在尝试将 NodeJS 插件加载到我正在构建的应用程序中,但我不知道如何操作.文档对此并不清楚.
I am new to Electron (Atom-shell), and I am trying to load a NodeJS plugin into the application I am building, but I don't know how. The documentation is not clear on that.
例如,我尝试在我的应用程序中使用 sqlite3 插件,我使用了 npm install sqlite3,它已成功安装.但是当我尝试调用它 var sqlite = require('sqlite3') 时,应用程序会抛出错误.是否还有其他我不知道的步骤?
For instance, I am trying to use sqlite3 plugin in my app, I used npm install sqlite3, and it was successfully installed. But the application throws and error when I try to call it var sqlite = require('sqlite3'). Are there any further steps I am not aware of ?
谢谢.
推荐答案
对于纯 JS(即非原生)模块,您需要以下内容:
For pure JS (i.e. not native) modules you need the following:
- 将模块列在您的
package.json依赖项中 - 让 electron 知道在哪里可以找到模块(例如
export NODE_PATH=/PATH/TO/node_module)
- Have the module listed in your
package.jsondependencies - Let electron know where to find the module (e.g.
export NODE_PATH=/PATH/TO/node_module)
第一个要求很明显,第二个要求源于this issue.
The first requirement is obvious and the second has its roots in this issue.
对于使用 C++ 绑定的本机节点模块(例如 sqlite3),您需要针对电子标头构建它们才能工作.根据 电子文档,最简单的方法是:
For native node modules (such as sqlite3) which use C++ bindings, you need to build them against electron headers to work. According to electron docs, the easiest way to do that would be:
npm install --save-dev electron-rebuild
# Every time you run npm install, run this
./node_modules/.bin/electron-rebuild
这篇关于在 Electron 中使用 NodeJS 插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Electron 中使用 NodeJS 插件
基础教程推荐
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
