简体   繁体   中英

Error: The specified module could not be found

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.

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.

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 (eg 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM