I'm implementing face detection using MediaPipe in a React/TypeScript application with Vite. While the code works perfectly in development mode (npm run dev), I'm getting a constructor error when building and serving the production build (npm run build).
Uncaught TypeError: face_detection.FaceDetection is not a constructor
at main-CLsce9aG.js:31922:48179
at Qj (main-CLsce9aG.js:38:27193)
at Hk (main-CLsce9aG.js:38:47511)
at main-CLsce9aG.js:38:45609
at X_ (main-CLsce9aG.js:23:1729)
at MessagePort.p2 (main-CLsce9aG.js:23:2141)
Here is my code:
import * as FaceDetection from '@mediapipe/face_detection';
export const useFaceDetection= ( options: FaceDetectionOptions = {}): UseFaceDetectionReturn => {
useEffect(() => {
const faceDetection = new FaceDetection.FaceDetection({
locateFile: (file) => {
return `/@mediapipe/[email protected]/${file}`;
}
});
....
...Rest
}
Question
1.Why is the FaceDetection constructor not available in the production build? 2.How can I properly initialize MediaPipe Face Detection in a Vite/React production build?
Any help would be greatly appreciated!