# OpenCV.js built file not working

**URL:** <https://forum.opencv.org/t/opencv-js-built-file-not-working/14866>\
**Category:** Uncategorized\
**Tags:** opencvjs\
**Created:** [October 15, 2023, 8:28pm UTC](https://forum.opencv.org/t/opencv-js-built-file-not-working/14866 "2023-10-15T20:28:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tarek](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/tarek/32/10512_2.png) [@tarek](https://forum.opencv.org/u/tarek)\
**Post date:** [October 15, 2023, 8:28pm UTC](https://forum.opencv.org/t/opencv-js-built-file-not-working/14866/1 "2023-10-15T20:28:16Z")

</div>

Hey, I’ve been brawling this setup process forever and am hoping someone can help.  
I built opencv.js from source using this command:

```auto
emcmake python3 opencv/platforms/js/build_js.py build_asm --disable_wasm --emscripten_dir="/mnt/c/users/magma/emsdk/upstream/emscripten" --cmake_option="-DCMAKE_TOOLCHAIN_FILE=/mnt/c/Users/magma/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake" --cmake_option="-DCMAKE_CROSSCOMPILING_EMULATOR=/mnt/c/Users/magma/emsdk/node/16.20.0_64bit/bin/node"

```

It builds flawlessly, and passes most of the tests (which I think is intended). However, the opencv.js I built doesn’t seem to work. When I load it and attempt to use an openCV function, I get this error:

```auto
Uncaught TypeError: cv.getBuildInformation is not a function
    at opencvcheck (example2.html:12:20)
    at HTMLScriptElement.onload (example2.html:16:33)

```

When I replace the opencv.js file I built with the downloadable base one, the same program works. So clearly something is up with the process which I used to build my opencv.js, but the command I ran should work and no errors are brought up when I build it.

For what it’s worth, this is the program I’m running (which doesn’t work with my opencv.js, but works with the downloadable default opencv.js):

```auto
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title> Please work </title>
	</head>
	<body>
		<h2 id="checker" style="color: green;">OpenCV is loading...</h2>
		<script type="text/javascript">
			function opencvcheck(){
				document.getElementById('checker').innerHTML="OpenCV is ready. (hallelujah)"
				console.log(cv.getBuildInformation());
						}
		</script>
		<script async src="./opencv.js" onload="opencvcheck()"
			      type="text/javascript"></script>

	</body>
</html>

```

Please throw any ideas my way if you have em… this process is driving me crazy and I’ve scoured everywhere for answers to no avail

---

<div class="post-metadata">

**Author:** ![tarek](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/tarek/32/10512_2.png) [@tarek](https://forum.opencv.org/u/tarek)\
**Post date:** [October 16, 2023, 3:36pm UTC](https://forum.opencv.org/t/opencv-js-built-file-not-working/14866/2 "2023-10-16T15:36:14Z")

</div>

SOLVED:

For some reason, the downloadable opencv.js functions differently than the one I built with the aforementioned command. You need to fulfill the cv promise and use that promise’s value as you would use the var cv. Here’s how I edited the above code:

```auto
<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title> Please work </title>
</head>

<body>
	<h2 id="checker" style="color: green;">OpenCV is loading...</h2>
	<script type="text/javascript">
		function opencvcheck() {
			document.getElementById('checker').innerHTML = "OpenCV is ready. (hallelujah)"
			cv.then((aa) => { console.log(aa); console.log(aa.getBuildInformation()) })
		}
	</script>
	<script async src="./opencv.js" onload="opencvcheck()" type="text/javascript"></script>

</body>

</html>

```

This works with both the downloaded opencv.js and the one I built. Anyone know what arguments might’ve been used while building the downloadable opencv.js to get it to work like this? I’ll update if I figure it out.

---

<div class="post-metadata">

**Author:** ![andynewman](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@andynewman](https://forum.opencv.org/u/andynewman)\
**Post date:** [June 17, 2024, 2:36pm UTC](https://forum.opencv.org/t/opencv-js-built-file-not-working/14866/3 "2024-06-17T14:36:02Z")

</div>

Ahhh, I just saw this thread, thanks for this information.

Somehow I asked a similar question yesterday: [Building WASM Opencv.js: 'cv' is a Promise, not an Object](https://forum.opencv.org/t/building-wasm-opencv-js-cv-is-a-promise-not-an-object/17952)

It seems that:

- public-facing opencv.js builds use ‘cv’ as Object, and the WASM version requires further initialization through cv[‘onRuntimeInitialized’], as described here: [javascript - cv.Mat is not a constructor opencv - Stack Overflow](https://stackoverflow.com/a/63211547)

- manual opencv.js builds (as you and me experienced) show that, now, ‘cv’ is a Promise. onRuntimeInitialized no longer applies - seems like it.

> Anyone know what arguments might’ve been used while building the downloadable opencv.js to get it to work like this?

Did you get an explanation for the difference of behavior?
