node.js - Electron 无法从 node_modules 文件夹打开共享对象文件
问题描述
在 electron 上,节点模块vosk
需要访问一些位于node_modules/vosk/lib/
.
我现在遇到的问题是,当我这样做require('vosk')
并main.js
尝试执行我的 AppImage 文件时,我得到:
A JavaScript error occurred in the main process
Uncaught Exception:
Error: Dynamic Linking Error: /tmp/.mount_CantooClaxGf/resources/app.asar/node_modules/vosk/lib/linux-x86_64/libvosk.so: Cannot open the shared object: It's not a folder
at new DynamicLibrary (/tmp/.mount_CantooClaxGf/resources/app.asar/node_modules/ffi-napi/lib/dynamic_library.js:75:11)
at Object.Library (/tmp/.mount_CantooClaxGf/resources/app.asar/node_modules/ffi-napi/lib/library.js:47:10)
at Object.<anonymous> (/tmp/.mount_CantooClaxGf/resources/app.asar/node_modules/vosk/index.js:24:21)
at Module._compile (internal/modules/cjs/loader.js:1145:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1166:10)
at Module.load (internal/modules/cjs/loader.js:981:32)
at Module._load (internal/modules/cjs/loader.js:881:14)
at Function.Module._load (electron/js2c/asar.js:769:28)
at Module.require (internal/modules/cjs/loader.js:1023:19)
at require (internal/modules/cjs/helpers.js:77:18)
我尝试将 vosk 添加到构建中的文件中:
"build": {
"files": [
"dist/**/*",
"src/assets/icons/*",
"electron.js",
"package.json",
"assets/models/*",
"node_modules/vosk/lib/*"
],
我现在可以看到文件app.asar.unpacked/node_modules/vosk/lib/
夹中的文件,但是在执行应用程序时,我仍然遇到同样的错误。
我发现这个答案提到了一个黑客,但它没有解决我的问题,我仍然有完全相同的错误。
我应该如何以vosk
可以找到它们的方式打包共享对象?
解决方案
我可以用这个电子配置解决问题,将 vosk 的所有依赖项放在 extraResources 字段中:
"build": {
"extraResources": [
"node_modules/at-least-node/**/*",
"node_modules/builder-util-runtime/**/*",
"node_modules/debug/**/*",
"node_modules/ffi-napi/**/*",
"node_modules/fs-extra/**/*",
"node_modules/get-symbol-from-current-process-h/**/*",
"node_modules/get-uv-event-loop-napi-h/**/*",
"node_modules/graceful-fs/**/*",
"node_modules/jsonfile/**/*",
"node_modules/ms/**/*",
"node_modules/node-addon-api/**/*",
"node_modules/node-gyp-build/**/*",
"node_modules/ref-napi/**/*",
"node_modules/ref-struct-di/**/*",
"node_modules/sax/**/*",
"node_modules/universalify/**/*",
"assets/models/**/*"
],
"files": [
"dist/**/*",
"src/assets/icons/*",
"electron.js",
"package.json"
],
我还需要这个库。
它现在按预期工作
推荐阅读
- ios - 从核心数据加载数据以显示在集合视图上
- sql-server - 如何使用 SSIS 2019 读取平面文件并将其加载到 2 个不同的 SQL 表(不同的表结构)中
- javascript - Bootstrap 下拉按钮更改位置
- java - Eclipse 中的双精度浮点数与双精度浮点数
- c - 在我的程序显示其输出后,如何避免此回溯错误?
- c++ - 使用 for 循环填充向量列表
- javascript - 编写 Firefox 插件时如何覆盖 Web API 中的函数?
- jquery - 悬停时如何水平展开框以显示隐藏的文本
- tensorflow - 图表已断开:无法在“input_1”层获取张量 Tensor() 的值
- flutter - 如何将文件保存在 DOWNLOAD 文件夹中