24

I'm trying to use edge.js to execute some .NET code to print on windows in an Electron app. I've tried electron-edge and I've also tried manually building the edge.js modules targeting Electron following the instructions in the Electron docs, but I keep getting the following error when I try to use edge in the packaged app:

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)

I've checked the filesystem and the edge_nativeclr.node module does, in fact, exist. My suspicion is that I'm somehow not building the module correctly and it's perhaps targeting the wrong version of node still and so electron is unable to import the module.

I tried several different things, including following electron-edge's steps to manually update the build.bat and add the --target=1.4.12 --dist-url=https://atom.io/download/atom-shell flags to the node-gyp configure build.

I also set the following npm config options in my .npmrc:

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

And ran the build.bat, making sure to set the EDGE_NATIVE environment variable to point to the generated edge_nativeclr.node file, but got the same result.

Douglas Ludlow
  • 10,754
  • 6
  • 30
  • 54

2 Answers2

35

I finally got this figured out after banging my head against the keyboard for a couple days. I got some hints from electron-userland/electron-packager#217 and electron/electron#892, which pointed out that this error, "The specified module could not be found," could occur when the native module is missing a dependency, such as a .dll, and that you could use Dependency Walker to check the dependencies of any given .node module.

I loaded edge_nativeclr.node in Dependency Walker and noticed that VCRUNTIME140.DLL, the Visual Studio 2015 C runtime, was missing. Edge.js comes with the msvcr120.dll, the Visual Studio 2013 C runtime, but I'd been rebuilding the module with the msvs_version set to 2015.

Once I placed a copy of the vcruntime140.dll in the same directory as edge_nativeclr.node, everything started working as expected.

Douglas Ludlow
  • 10,754
  • 6
  • 30
  • 54
  • 2
    We had a similar issue. We used Dependency Walker as recommended above and determined that the electron packager was packaging things up as win32-x64. This looks for the 64 bit VCRUNTIME140.DLL. Note that you would need to have installed the 64 bit Visual Studio C++ Redistributable in order to have the correct dll. We had the 32 bit version installed originally. – Chadley08 Jan 11 '17 at 17:09
  • Either installed or packaged with your electron app. – Douglas Ludlow Jan 11 '17 at 17:10
  • It was installed separately. Can you include the redistributable with your electron app? – Chadley08 Jan 11 '17 at 17:14
  • No, I'm saying that you either need to install it separately or include it as part of your packaged electron app. In my case, I simply included it with the app, since it wasn't practical to require our users to install the extra library manually. – Douglas Ludlow Jan 11 '17 at 17:16
  • 1
    @Chadley08, yes you simply include the dll with your app, ensuring it's in the same folder as the `edge_nativeclr.node` file. – Douglas Ludlow Jan 11 '17 at 17:18
  • stuck with electron-edge-js .I have created an electron app. electronapp --> express --> edge . when i am trying to test electron-edge-js through express apis getting error edge as undefined at edge.js library – Vipin Shukla Jan 18 '19 at 10:52
  • 2
    Regarding Dependency Walker, a newer version can be found at https://github.com/lucasg/Dependencies – Wasabi Apr 19 '21 at 13:05
3

I also got this error even though I did have VC++ Redistributable x64 installed correctly. It turns out the error in my case was not actually a problem since everything worked fine (I was able to run the electron-quick-start app with electron-edge).

Even so, the author has fixed the install so that the error does not occur. https://github.com/kexplo/electron-edge/issues/25#issuecomment-272908409

Aside note, if you load edge_nativeclr.node in Dependency Walker, you will see the VCRUNTIME140.DLL resolved properly (e.g. under C:\Windows\System32 on my PC). However, you may see several question marks and errors. It turns out these are just due to some limitations in Dependency Walker and not an actual issue. See Dependency Walker: missing dlls

Community
  • 1
  • 1
victtim
  • 790
  • 5
  • 17