错误:找不到指定的模块

时间:2016-12-21 00:39:46

标签: node.js electron node-gyp edgejs

我正在尝试使用edge.js执行一些.NET代码,以便在Electron应用程序的Windows上打印。我已经尝试electron-edge了,我也尝试在instructions in the Electron docs之后手动构建针对Electron的edge.js模块,但是当我尝试在打包的应用中使用edge时,我一直收到以下错误:

Error: The specified module could not be found.
\\?\C:\path\to\app\app-1.0.0\resources\app.asar.unpacked\node_modules\edge\lib\native\win32\x64\6.5.0\edge_nativeclr.node
    at Error (native)
    at process.module.(anonymous function) (ELECTRON_ASAR.js:178:20)
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:178:20)
    at Object.Module._extensions..node (module.js:583:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:192:18)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)

我已经检查了文件系统,事实上,edge_nativeclr.node模块确实存在。我的怀疑是我不知道是不是正确地构建模块,它可能仍然针对错误版本的节点,因此电子无法导入模块。

我尝试了几种不同的方法,包括跟随electron-edge's steps手动更新build.bat并将--target=1.4.12 --dist-url=https://atom.io/download/atom-shell标记添加到node-gyp configure build

我还在.npmrc中设置了以下npm配置选项:

target=1.4.12
arch=x64
target_arch=x64
disturl=https://atom.io/download/electron
runtime=electron
build_from_source=true
msvs_version=2015

并运行build.bat,确保将EDGE_NATIVE环境变量设置为指向生成的edge_nativeclr.node文件,但结果相同。

2 个答案:

答案 0 :(得分:21)

我终于在把头撞到键盘上几天之后弄明白了。我从electron-userland/electron-packager#217electron/electron#892得到了一些提示,指出这个错误,"找不到指定的模块,"当本机模块缺少依赖项(例如.dll)时可能会发生,并且您可以使用Dependency Walker来检查任何给定.node模块的依赖项。

我在Dependency Walker中加载了edge_nativeclr.node,并注意到缺少Visual Studio 2015 C运行时VCRUNTIME140.DLL。 Edge.js附带了msvcr120.dll,即Visual Studio 2013 C运行时,但我一直在重建模块,msvs_version设置为2015。

vcruntime140.dll的副本放在与edge_nativeclr.node相同的目录中后,所有内容都按预期开始工作。

答案 1 :(得分:1)

即使我确实安装了VC ++ Redistributable x64,我也遇到了这个错误。事实证明,我的情况下的错误实际上并不是一个问题,因为一切正常(我能够使用电子边缘运行电子快速启动应用程序)。

即便如此,作者已修复安装,以免发生错误。 https://github.com/kexplo/electron-edge/issues/25#issuecomment-272908409

除此之外,如果在Dependency Walker中加载edge_nativeclr.node,您将看到VCRUNTIME140.DLL已正确解析(例如,在我的PC上的C:\ Windows \ System32下)。但是,您可能会看到几个问号和错误。事实证明,这些只是由于Dependency Walker的一些限制而不是实际问题。见Dependency Walker: missing dlls