opencv4nodejs icon indicating copy to clipboard operation
opencv4nodejs copied to clipboard

Module did not self-register error when using Electron

Open sonesson89 opened this issue 3 years ago • 4 comments

OpenCV version: 4.6.0 Node version: 16.16.0 Electron version: 20.0.1 Electron-rebuild version: 3.2.9 @u4/opencv4nodejs version: 6.2.1 @u4/opencv-build version: 0.5.3 OS: Windows 10 x64

I have Visual Studio and Windows Build Tools already installed.

Variables in package.json:

"opencv4nodejs": {
    "disableAutoBuild": "1",
    "OPENCV_INCLUDE_DIR": "C:\\opencv\\build\\include",
    "OPENCV_LIB_DIR": "C:\\opencv\\build\\x64\\vc14\\lib",
    "OPENCV_BIN_DIR": "C:\\opencv\\build\\x64\\vc14\\bin"
  },

I finally managed to get opencv4nodejs to work. But it only works in my Nodejs runtime, when running node scripts directly in terminal. But with Electron I cannot get it to work.

After having installed all my packages with npm install I then build opencv with the npm-script that is defined as: build-opencv --nobuild rebuild. This seems to be succesful. I can then run scripts in terminal that use @u4/opencv4nodejs. However if I launch an Electron app using electron . I get the following error:

infoError: Module did not self-register: '\\?\C:\Git\Borghild\node_modules\@u4\opencv4nodejs\build\Release\opencv4nodejs.node'.
    at process.func [as dlopen] (node:electron/js2c/asar_bundle:5:1812)
    at Module._extensions..node (node:internal/modules/cjs/loader:1205:18)
    at Object.func [as .node] (node:electron/js2c/asar_bundle:5:1812)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Module._load (node:internal/modules/cjs/loader:829:12)
    at c._load (node:electron/js2c/asar_bundle:5:13343)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at getOpenCV (C:\Git\Borghild\node_modules\@u4\opencv4nodejs\lib\cvloader.js:55:23)
    at loadOpenCV (C:\Git\Borghild\node_modules\@u4\opencv4nodejs\lib\opencv4nodejs.js:9:43) {
  code: 'ERR_DLOPEN_FAILED'
}

If I got into the build folder for opencv4nodejs I can see that the build files are there, and like I said, it works in regular nodejs scripts but just not in Electron.

image


If I try to rebuild electron using ./node_modules/.bin/electron-rebuild that doesn't seem to help at all.

I then try to rebuild electron with build-opencv --electron --version 4.6.0 build (copied from the readme of this project). That doesn't work because then I get errors, please see file:

electron-rebuild-error.txt

sonesson89 avatar Aug 13 '22 14:08 sonesson89

I'm still not using Electron, can not help with that.

UrielCh avatar Aug 31 '22 05:08 UrielCh

opencv4nodejs will not compile against electron version >18 at the moment due to a changed interface in v8 api.

There was a pull request for the nan package that seemed to fix this compile issue but they changed it to a different approach and closed the official pull request, I forked that branch to keep my build alive. Here is a package.json that will build correctly for latest electron.

  "name": "electron20-opencv",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "electron .",
    "electron-rebuild": "build-opencv --electron --version 4.6.0 build"
  },
  "author": "",
  "license": "MIT",
  "dependencies": {
    "@u4/opencv4nodejs": "^6.2.1",
    "buffer-to-data-url": "^1.0.0",
    "electron": "^20.1.0",
    "nan": "github:universe-bot/nan#remove_accessor_signature"
  },
  "devDependencies": {
    "electron-rebuild": "^3.2.9"
  },
  "@u4/opencv4nodejs": {
    "autoBuildOpencvVersion": "1",
    "autoBuildWithoutContrib": "1"
  }
}

deadphoenix8091 avatar Sep 09 '22 21:09 deadphoenix8091

@UrielCh

Here is the source of that info along with an explanation to the cause of this issue. This should affect any javascript runtime based on recent v8 so possibly new nodejs versions too?

https://github.com/electron/electron/issues/35193#issuecomment-1204143737

deadphoenix8091 avatar Sep 09 '22 21:09 deadphoenix8091

I have same error as aformentioned, I've tried installing electron 18, adding "nan": "github:universe-bot/nan#remove_accessor_signature" as well as trying solution from link mentioned by @deadphoenix8091. However it still doesn't work. I've installed opencv using chocolatey v4.6.0, I'm using Win11. Is there any solution for this, at least temporary?

Maybe I'm doing something wrong? Clean install of my project is done by those commands: yarn npx build-opencv --version 4.6.0 rebuild Then I run it by: concurrently -k \"cross-env BROWSER=none yarn start\" \"wait-on http://localhost:3000 && electronmon .\" but using electron . doesn't work either

Error:

Error: require("[33mC:\Users\filip\Desktop\perihelion\node_modules\@u4\opencv4nodejs\build\Release\opencv4nodejs[39m"); 
          Failed with: [31mModule did not self-register: '\\?\C:\Users\filip\Desktop\perihelion\node_modules\@u4\opencv4nodejs\build\Release\opencv4nodejs.node'.[39m
          
    at getOpenCV (VM131 C:\Users\filip\Desktop\perihelion\node_modules\@u4\opencv4nodejs\lib\cvloader.js:104:23)
    at loadOpenCV (VM122 C:\Users\filip\Desktop\perihelion\node_modules\@u4\opencv4nodejs\lib\opencv4nodejs.js:9:43)
    at Object.<anonymous> (VM122 C:\Users\filip\Desktop\perihelion\node_modules\@u4\opencv4nodejs\lib\opencv4nodejs.js:24:12)
    at Object.<anonymous> (VM122 C:\Users\filip\Desktop\perihelion\node_modules\@u4\opencv4nodejs\lib\opencv4nodejs.js:33:3)
    at Module._compile (VM94 loader:1116:14)
    at Object.Module._extensions..js (VM94 loader:1169:10)
    at Module.load (VM94 loader:988:32)
    at Module._load (VM94 loader:829:12)
    at Function.c._load (VM110 asar_bundle:5:13343)
    at Function.i._load (VM113 renderer_init:33:356)

kostnerek avatar Nov 16 '22 12:11 kostnerek