mediapipe: TypeError: hands.Hands is not a constructor
System information (Please provide as much relevant information as possible)
- React/typescript
- @mediapipe/hands version 0.4.1646424915
Describe the current behavior:
When using the default code example, I get the error TypeError: hands.Hands is not a constructor
code:
const hands = new mpHands.Hands({
locateFile: (_file: string) => {
return `https://cdn.jsdelivr.net/npm/@mediapipe/hands@0.4.1646424915/hands.js`;
}
});
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 27
We are in the process of creating new JS libraries that should not have this issue, as they are built using ESM. While they have not yet reached feature parity, you can find them here: https://www.npmjs.com/package/@mediapipe/tasks-vision, https://www.npmjs.com/package/@mediapipe/tasks-text, https://www.npmjs.com/package/@mediapipe/tasks-audio. The libraries are also open sourced in this repo: https://github.com/google/mediapipe/tree/master/mediapipe/tasks/web
Due to our existing infrastructure, it is difficult for us to release the existing libraries using ESM.
Hello @taha-azzabi @nohr
This seems to be happening due to the Rollup CommonJS plugin, since this plugin can’t work with obfuscated packages and the JS source code for MediaPipe is not public. Rollup uses static analysis to determine its exports.
We are working on a solution to unveal the JS code so that this issue does not arise. Meanwhile, can you refer to https://github.com/google/mediapipe/issues/2883#issuecomment-1060454290 and let us know if this works for you? PS: The link by the author has changed to this link
I’m facing a similar issue importing Hollistic in a vite (astro) app. Occurs in production.
I also face this issue but only in production build, it happens with Camera in camera_utils too. For now i get Camera and Hands from cdn link instead of npm package and it work, the versions are same but npm package doesnt work in build