在分叉过程中需要sqlite3本机模块时,电子崩溃 [英] Electron crashes when requiring sqlite3 native module in forked process
问题描述
我试图在带有电子的子进程中使用sqlite3模块,但是出现未定义符号的错误.而且,仅当我从电子的node.js运行程序时才会发生错误,但是当我从通常的node.js运行程序时,一切正常.我认为问题可能与sqlite3模块的本地性"有关,我尝试了 electron-rebuild
, npm --build-from-source
,它们没有帮助
I'm trying to use sqlite3 module in a child process with electron, but I get error of undefined symbol. Also, the error happens only when I run the program from electron's node.js, but when I run the program from usual node.js everything works fine. I think the problem may be related to 'nativeness' of sqlite3 module, and I tried electron-rebuild
, npm --build-from-source
, they didn't help.
main.js:
const { fork } = require('child_process');
fork('fork');
fork.js:
const sqlite3 = require('sqlite3');
package.json:
package.json:
{
"name": "bugreproduce_sqlite",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"sqlite3": "^4.0.2"
},
"devDependencies": {
"electron": "^3.0.5"
}
}
输出:
> ./node_modules/electron/dist/electron .
/home/myuser/Programming/javascript/bugreproduce_sqlite/node_modules/electron/dist/electron: symbol lookup error: /home/myuser/Programming/javascript/bugreproduce_sqlite/node_modules/sqlite3/lib/binding/node-v64-linux-x64/node_sqlite3.node: undefined symbol: _ZN2v816FunctionTemplate3NewEPNS_7IsolateEPFvRKNS_20FunctionCallbackInfoINS_5ValueEEEENS_5LocalIS4_EENSA_INS_9SignatureEEEiNS_19ConstructorBehaviorENS_14SideEffectTypeE
推荐答案
我找到了根本问题.这是相关的问题和在GitHub上拉出请求2 .
I found the root problem. Here is the relevant issue and pull request 1, pull request 2 on GitHub.
我要临时解决此问题的步骤是:
My steps to temporarily fixing the problem were:
- 克隆节点-gyp git仓库
-
checkout
到sqlite3想要的版本(目前为0.10.3) - 从第二个请求请求中应用补丁
- 从主项目文件夹中通过
npm install ../path/to/patched/node-pre-gyp
安装此修补的Node-pre-gyp -
npm i-从源构建sqlite3
(不确定是否需要此命令)和主项目中的./node_modules/.bin/electron-rebuild
文件夹(我安装了电子重建) -
调用设置了电子版本的
fork
,如下所示:
- Clone node-pre-gyp git repository
checkout
to the version sqlite3 wants(0.10.3 at the moment)- Apply patch from the second pull request
- Install this patched node-pre-gyp via
npm install ../path/to/patched/node-pre-gyp
from the main project folder npm i --build-from-source sqlite3
(not sure this command is needed) and./node_modules/.bin/electron-rebuild
from the main project folder (I installed electron-rebuild)call
fork
with electron version set, like this:
fork('fork',[],{信封:{ELECTRON_VERSION:"3.0.5"}});
这是一个hack,但它似乎可以正常工作.希望这个问题能在上游得到解决.
This is a hack, but it seems to work. Hope the problem will be fixed in upstream.
已固定了拉取请求链接(我使用了第二个拉取请求,而不是第一个)
edited: fixed pull request link (I used the second pull request, not the first)
这篇关于在分叉过程中需要sqlite3本机模块时,电子崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!