无法在 Windows 上使用电子 4.0.6 加载某些本机节点 js 模块 [英] Unable to load some native node js modules with electron 4.0.6 on Windows

查看:23
本文介绍了无法在 Windows 上使用电子 4.0.6 加载某些本机节点 js 模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的应用程序从电子 1.8.1 升级到 4.0.6.我正在使用多个本机节点 js 模块.它们都编译成功(或预构建的二进制文件可用).

I am trying to upgrade my application from electron 1.8.1 to 4.0.6. I am using multiple native node js modules. They all compile successfully (or prebuilt binaries are available).

在需要其中一个模块时出现以下错误.

I am getting following error when requiring one of the modules.

XXXX\node_modules\electron-log\renderer.js:34 [10:14:51.109] Failed to add 
module. Error: Error: The specified procedure could not be found.
\?\XXXXX\node_modules\pc-ble-driver-js\build\Release\pc-ble-driver-js- 
 sd_api_v2.node

而其他本机模块(如串行端口、noble-uwp)正在加载并正常工作.

Whereas other native modules (such as serialport, noble-uwp) are loading and working fine.

此错误通常表示缺少所需的 DLL.我已经使用 Dependency Walker (http://www.dependencywalker.com/) 来检查依赖关系,但我无法确定错误.我试图比较有效模块的依赖关系和我得到上述错误的模块的依赖关系.我没有看到明显的差异.

This error generally indicates that a required DLL is missing. I have used Dependency Walker (http://www.dependencywalker.com/) to check the dependencies but I couldn't nail down the error. I tried to compare dependencies for module that works and the one for which I get above error. I didn't see obvious differences.

我安装了 Visual Studio 2015.我还安装了 VC++ 2015 可再发行组件.

I have Visual Studio 2015 installed. I also have VC++ 2015 redistributable installed.

我的电子特定依赖项是:

My electron specific dependencies are:

"devDependencies": {
    "electron": "~4.0.6",
    "electron-builder": "~20.39.0",
    "electron-rebuild": "^1.8.4"
},

我使用的是 node-js 10.15.3.

I am using node-js 10.15.3.

我注意到,在电子 3 之前,node_modules/electron/dist 存在许多 DLL.电子 4 不存在这些 DLL.

I have noticed that till electron 3, node_modules/electron/dist had many DLLs present. These DLLs are not present with electron 4.

本地模块是否需要安装任何其他依赖项才能与电子 4 一起使用?

Are any additional dependencies needed to be installed for native modules to work with electron 4?

推荐答案

我让它起作用了.

为了让原生 node js 模块在 Windows 上与电子 4 一起工作,它需要使用延迟加载钩子"进行编译.更多信息:https://electronjs.org/docs/tutorial/using-native-node-modules#a-note-about-win_delay_load_hookhttps://github.com/nodejs/node-addon-api/issues/269#issuecomment-455580129.进行这些更改后,我失败的模块开始工作.

For native node js modules to work with electron 4 on Windows, it needs to be compiled with "Delay Load Hook". More info: https://electronjs.org/docs/tutorial/using-native-node-modules#a-note-about-win_delay_load_hook and https://github.com/nodejs/node-addon-api/issues/269#issuecomment-455580129. After making these changes my failing module started to work.

关于为什么其他模块在没有这些更改的情况下工作是因为它们直接使用 node-gyp.它负责使用这个钩子.

About why other modules worked without these changes is because they use node-gyp directly. It takes care of using this hook.

我失败的模块使用了 cmake-js,这需要上述额外的更改.

My failing module uses cmake-js, which needs above mentioned additional changes.

这篇关于无法在 Windows 上使用电子 4.0.6 加载某些本机节点 js 模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆