Closed wuiyang closed 5 months ago
thx for the detailed report.
Yes, you are right. The mediapipe import does caused the error.
For the AFRAME version, turns out it's a bug introduced in vite v4.1.something. It incorrectly compile one of the file. I did a stupid workaround to by-pass this error until vite fix it.
Anyway, they should be fixed in lastest version 1.2.2
Version
1.2.1
Reproduction link
ThreeJS: https://hiukim.github.io/mind-ar-js-doc/face-tracking-samples/three.html AFrame: https://hiukim.github.io/mind-ar-js-doc/face-tracking-samples/minimal.html Note: need to edit to use version 1.2.1 version of MindAR
Steps to reproduce
What is expected?
Both ThreeJS version and AFrame version should be able to start up MindAR Face Tracking sample without issue.
What is actually happening?
For ThreeJS
Received error
Uncaught (in promise) TypeError: pB.FaceMesh is not a constructor
when starting MindAR system for face tracking in ThreeJS version.For AFrame
Uncaught SyntaxError: return not in functionmindar-face-aframe.prod.js:1:1647
Investigation
This issue is occurred in bundle script, where the import script below is compiled into wrong code.
For ThreeJS
Import script: https://github.com/hiukim/mind-ar-js/blob/41e3e264c6861c45512364d724c620412cc67180/src/face-target/face-mesh-helper.js#L1
Compiled code:
For AFrame
The bundled code having incorrect code, where it has
return
keyword at the root level (outside of a function).Solution
I found out that vite production config has specified external package, but missing some of the other external packages.Including@mediapipe/face_mesh
in external packages fixed the issue.Edited Turns out it's
@mediapipe/face_mesh
package caused the issue, it is a IIFE package, but compiler seems to not handling it correctly.For ThreeJS
The fix is revert changes made in
face-mesh-helper.js
.Revert the import back to original import method as mentioned in this commit https://github.com/hiukim/mind-ar-js/commit/c747438a1bf7f8743aed04a996e8dc1cedb9a1ea .
https://github.com/hiukim/mind-ar-js/blob/41e3e264c6861c45512364d724c620412cc67180/src/face-target/face-mesh-helper.js#L1
For AFrame
I have not found a fix for AFrame compiled code.