alex8088 / electron-vite

Next generation Electron build tooling based on Vite 新一代 Electron 开发构建工具,支持源代码保护
https://electron-vite.org
MIT License
3.57k stars 153 forks source link

App threw an error during load Error: Module did not self-register 'xxx/node_modules/@u4/opencv4nodejs/build/Release/opencv4nodejs.node' #593

Closed xiatian12345 closed 3 months ago

xiatian12345 commented 3 months ago

Describe the bug

  1. npm create @quick-start/electron@latest create the electron-vite-demo

  2. npm install @u4/opencv4nodejs install the opencv4nodejs

  3. add some code in package.json"electron-rebuild": "build-opencv --electron --version 4.5.4 build" and then build the electron npm run electron-rebuild

  4. create a test.js and write some code const cv = require('@u4/opencv4nodejs') console.log(cv.getVersion())

  5. run the test.js and get the correct result:[ 4, 10, 0 ]

  6. in main/index.js add same code const cv = require('@u4/opencv4nodejs') console.log(cv.getVersion()) then run the project by npm run dev,and then got the error as title!

I am confiued by this error,please help me.

(base) ➜ electron-vite-demo brew info opencv
==> opencv: stable 4.10.0 (bottled), HEAD Open source computer vision library https://opencv.org/ Installed /usr/local/Cellar/opencv/4.10.0_2 (982 files, 258.5MB) * Poured from bottle using the formulae.brew.sh API on 2024-08-14 at 21:06:42 From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/o/opencv.rb License: Apache-2.0 ==> Dependencies Build: cmake ✔, pkg-config ✔, python-setuptools ✔ Required: abseil ✔, ceres-solver ✔, eigen ✔, ffmpeg@6 ✔, freetype ✔, gflags ✔, glog ✔, harfbuzz ✔, jpeg-turbo ✔, libpng ✔, libtiff ✔, numpy ✔, openblas ✔, openexr ✔, openjpeg ✔, openvino ✔, protobuf ✔, python@3.12 ✔, tbb ✔, tesseract ✔, vtk ✔, webp ✔, glew ✔, imath ✔, jsoncpp ✔, libarchive ✔ ==> Options --HEAD Install HEAD version

(base) ➜ electron-vite-demo node --version v18.20.3

(base) ➜ electron-vite-demo electron --version v31.2.1

Electron-Vite Version

3.3.0

Electron Version

v31.2.1

Vite Version

5.4.1

Validations

alex8088 commented 3 months ago

You should use ES syntax to import module.

xiatian12345 commented 3 months ago

yes,but got same error.

You should use ES syntax to import module.

xiatian12345 commented 3 months ago

i solved it by:delete node_modules and reinstall...