Problem with --buildRoot Error: No build found and Bin path not found.
OpenCV version (example 3.4.1): 4.7.0, 4.6.0 With OpenCV-contrib? (extra modules): yes OS: Windows 10 NodeJS: 18.13.0 NPM: 8.6.0
I'm using auto build, everything went fine, no error.
I use this build script
"electron-rebuild": "build-opencv --electron --version 4.7.0 --buildRoot C:/opencv build"
The build went through with no error.
But then I got the following errors when I try using OpenCV with electron (just require('@u4/opencv4nodejs')).
Error: No build found in D:\...\node_modules\@u4\opencv-build\dist you should launch opencv-build-npm once

so I try install OpenCV again without changing root. using this script.
"electron-rebuild2": "build-opencv --electron --version 4.7.0 build"
then I got another error message... saying it need v4.6.0 (but I installed 4.7.0... why?)
ERROR Error: No build of version 4.6.0 found in D:\...\node_modules\@u4\opencv-build\dist you should launch opencv-build-npm

so I try install 4.6.0 using
"electron-rebuild3": "build-opencv --electron --version 4.6.0 build"
build finished successfully, but I got another error.
main.ts:12 ERROR Error: require("[33mD:\Works\project\gee\app-new\node_modules\@u4\opencv4nodejs\build\Release\opencv4nodejs[39m");
Failed with: [31mThe specified module could not be found.
\\?\D:\Works\project\gee\app-new\node_modules\@u4\opencv4nodejs\build\Release\opencv4nodejs.node[39m, openCV module looks broken, clean you builds directory and rebuild everything
rm -r <path to your build directory>
npx build-opencv --version 4.6.0 rebuild

I try rebuild from scratch again and still getting the same error. so I try searching for a way to explicitly set opencv version for this project. I try put this in package.json
"opencv4nodejs": {
"autoBuildOpencvVersion": "4.7.0"
}
now the error changed to
ERROR Error: opencv binary dir does not exist: C:\tools\opencv\build\bin

so I try again with
"opencv4nodejs": {
"autoBuildOpencvVersion": "4.7.0",
"opencvBinDir": "./node_modules/@u4/opencv-build/dist/opencv-4.7.0-8b1ea/build/x64/vc16/bin"
}
still got the same error... but then I try changing version to 4.6.0 but 4.7.0 lib like this
"opencv4nodejs": {
"autoBuildOpencvVersion": "4.6.0",
"opencvBinDir": "./node_modules/@u4/opencv-build/dist/opencv-4.7.0-8b1ea/build/x64/vc16/bin"
}
now it working... why? why I have to put build version as 4.6.0 but bin directory as 4.7.0 ?
is there any explanation ? is there any config I needed to do but missed?
if you need the project files I can send zipped.
Here is my package.json
{
"name": "angular-electron",
"version": "11.2.0",
"description": "Angular 14 with Electron 21 (Typescript + SASS + Hot Reload)",
"homepage": "https://github.com/maximegris/angular-electron",
"author": {
"name": "Maxime GRIS",
"email": "[email protected]"
},
"keywords": [
"angular",
"angular 14",
"electron",
"electron 19",
"nodejs",
"typescript",
"playwright",
"eslint",
"sass",
"windows",
"mac",
"linux"
],
"main": "app/main.js",
"private": true,
"scripts": {
"postinstall": "electron-builder install-app-deps",
"ng": "ng",
"start": "npm-run-all -p electron:serve ng:serve",
"ng:serve": "ng serve -c web -o",
"build": "npm run electron:serve-tsc && ng build --base-href ./",
"build:dev": "npm run build -- -c dev",
"build:prod": "npm run build -- -c production",
"web:build": "npm run build -- -c web-production",
"electron": "electron",
"electron:serve-tsc": "tsc -p tsconfig.serve.json",
"electron:serve": "wait-on tcp:4200 && npm run electron:serve-tsc && electron . --serve",
"electron:local": "npm run build:prod && electron .",
"electron:build": "npm run build:prod && electron-builder build --publish=never",
"electron-rebuild": "build-opencv --electron --version 4.7.0 --buildRoot C:/opencv build",
"electron-rebuild2": "build-opencv --electron --version 4.7.0 build",
"electron-rebuild3": "build-opencv --electron --version 4.6.0 build",
"test": "ng test --watch=false",
"test:watch": "ng test",
"e2e": "npm run build:prod && playwright test -c e2e/playwright.config.ts e2e/",
"e2e:show-trace": "playwright show-trace e2e/tracing/trace.zip",
"version": "conventional-changelog -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md",
"lint": "ng lint"
},
"dependencies": {
"@angular/common": "15.1.2",
"@angular/compiler": "15.1.2",
"@angular/core": "15.1.2",
"@angular/forms": "15.1.2",
"@angular/language-service": "15.1.2",
"@angular/platform-browser": "15.1.2",
"@angular/platform-browser-dynamic": "15.1.2",
"@angular/router": "15.1.2",
"@u4/opencv4nodejs": "6.4.1",
"rxjs": "7.5.7",
"tslib": "^2.4.0",
"zone.js": "~0.11.8"
},
"devDependencies": {
"@angular-builders/custom-webpack": "15.0.0",
"@angular-devkit/build-angular": "15.1.3",
"@angular-eslint/builder": "15.2.0",
"@angular-eslint/eslint-plugin": "15.2.0",
"@angular-eslint/eslint-plugin-template": "15.2.0",
"@angular-eslint/schematics": "15.2.0",
"@angular-eslint/template-parser": "15.2.0",
"@angular/cli": "15.1.3",
"@angular/compiler-cli": "15.1.2",
"@electron/rebuild": "3.2.10",
"@ngx-translate/core": "14.0.0",
"@ngx-translate/http-loader": "7.0.0",
"@playwright/test": "1.27.1",
"@types/jasmine": "4.3.0",
"@types/jasminewd2": "2.0.10",
"@types/node": "18.11.0",
"@typescript-eslint/eslint-plugin": "^5.43.0",
"@typescript-eslint/parser": "^5.43.0",
"conventional-changelog-cli": "2.2.2",
"electron": "22.0.3",
"electron-builder": "23.6.0",
"electron-debug": "3.2.0",
"electron-reloader": "1.2.3",
"eslint": "^8.28.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-jsdoc": "39.3.6",
"eslint-plugin-prefer-arrow": "1.2.3",
"jasmine-core": "4.4.0",
"jasmine-spec-reporter": "7.0.0",
"karma": "6.4.1",
"karma-coverage-istanbul-reporter": "3.0.3",
"karma-electron": "7.3.0",
"karma-jasmine": "5.1.0",
"karma-jasmine-html-reporter": "2.0.0",
"node-polyfill-webpack-plugin": "2.0.1",
"npm-run-all": "4.1.5",
"playwright": "1.27.1",
"ts-node": "10.9.1",
"typescript": "4.8.4",
"wait-on": "6.0.1",
"webdriver-manager": "12.1.8"
},
"engines": {
"node": ">= 14.15.0"
},
"browserslist": [
"chrome 100"
],
"opencv4nodejs": {
"autoBuildOpencvVersion": "4.6.0",
"opencvBinDir": "./node_modules/@u4/opencv-build/dist/opencv-4.7.0-8b1ea/build/x64/vc16/bin"
}
}
here is my ts-config.json
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"module": "es2020",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowJs": true,
"target": "ES2022",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"es2016",
"es2015",
"dom"
],
"useDefineForClassFields": false
},
"exclude": [
"node_modules"
],
"angularCompilerOptions": {
"strictTemplates": true,
"fullTemplateTypeCheck": true,
"annotateForClosureCompiler": true,
"strictInjectionParameters": true,
"skipTemplateCodegen": false,
"preserveWhitespaces": true,
"skipMetadataEmit": false,
"disableTypeScriptVersionCheck": true
}
}
here is the build output

when I build electron package I got the same error as above.
Error: No build of version 4.6.0 found in C:\Users\nitip\AppData\Local\Temp\2KuuRDgr97I79JYqyv7VCI3osY8\resources\app.asar\node_modules\@u4\opencv-build\dist you should launch opencv-build-npm
what should I do ?
1st: do not use 4.7.0 use 4.6.0
2nd: define an env variable OPENCV_BUILD_ROOT=c:/opencv
3th: never use "opencvBinDir" to point a lib built by @u4/opencv-build
4th: I'm still not using electron....
Thank you for the reply. I see.
I resolved the problem at developing time by setting OPENCV_BUILD_ROOT=c:/opencv environment variable.
Is there any other way so that I didn't have to set environment variable every times I wanted to run the app?
maybe a way to specify build root in package.json? i tried buildRoot and openCVBuildRoot it didn't works.
the ERROR Error: opencv binary dir does not exist problem still occur when packaging final app. I will try to find the way.