Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined is not a constructor #1976

Closed
FladioArmandika opened this issue May 4, 2021 · 20 comments
Closed

undefined is not a constructor #1976

FladioArmandika opened this issue May 4, 2021 · 20 comments
Assignees
Labels
legacy:face detection Issues related to Face Detection platform:javascript MediaPipe Javascript issues type:support General questions

Comments

@FladioArmandika
Copy link

i use npm install @mediapipe/face_detection

and import
import { FaceDetection } from '@mediapipe/face_detection' and
import { FaceDetection } from '@mediapipe/face_detection/face_detection';

and do
let faceDetection = new FaceDetection();

but it tells me undefined is not a constructor (evaluating 'new _face_detection.FaceDetection()')

would you help me? or give some example for implementing it?

@sgowroji sgowroji self-assigned this May 4, 2021
@sgowroji sgowroji added platform:javascript MediaPipe Javascript issues legacy:face detection Issues related to Face Detection stat:awaiting response Waiting for user response type:support General questions labels May 4, 2021
@sgowroji
Copy link

sgowroji commented May 4, 2021

Hi @FladioArmandika, Could you please share your code. Assuming its more an import error, Please recheck your imports. Thanks!

@FladioArmandika
Copy link
Author

FladioArmandika commented May 4, 2021

import { FaceDetection } from '@mediapipe/face_detection';
let faceDetection = new FaceDetection();

i also try
import { FaceDetection } from '@mediapipe/face_detection/face_detection';
as they did in this

is there anything wrong?

@sgowroji sgowroji assigned mhays-google and unassigned sgowroji May 4, 2021
@sgowroji sgowroji added stat:awaiting googler Waiting for Google Engineer's Response and removed stat:awaiting response Waiting for user response labels May 4, 2021
@mhays-google
Copy link
Contributor

Hi! Can you try using "@mediapipe/face_detection": "^0.3" in your dependencies? The package.json I was using was in shambles. Also, to save you time, if you didn't already see this, you'll need to change locateFile to grab the files from your npm_modules. Something like:

   faceDetection = new FaceDetection({
      locateFile: (path, base) => {
        return `base/node_modules/@mediapipe/face_detection/${path}`;
      }
    });

@sgowroji sgowroji added stat:awaiting response Waiting for user response and removed stat:awaiting googler Waiting for Google Engineer's Response labels May 6, 2021
@sgowroji
Copy link

sgowroji commented May 6, 2021

Hi @FladioArmandika, Have a look at the above comment. Thanks!

@FladioArmandika
Copy link
Author

TypeError: undefined is not a constructor (evaluating 'new _face_detection.FaceDetection')

I change to ^0.3 and change the locateFile

but still got the same error like before :(

@sgowroji sgowroji added stat:awaiting googler Waiting for Google Engineer's Response and removed stat:awaiting response Waiting for user response labels May 19, 2021
@DanielWFrancis
Copy link

DanielWFrancis commented Jun 30, 2021

I also get the same issues with Pose. Have changed my initialization to

const pose = new Pose({
  locateFile: (file) => {
    return `node_modules/@mediapipe/pose/${file}`;
  }
});

but I get the same undefined is not a constructor.

I don't see any examples of importing from the npm-installed libraries anywhere... not sure if I'm doing this right?

@jomariya23156
Copy link

I'm getting the same issues here with pose. Has anyone fixed this?

@mhays-google
Copy link
Contributor

mhays-google commented Jul 29, 2021 via email

@sgowroji sgowroji added stat:awaiting response Waiting for user response and removed stat:awaiting googler Waiting for Google Engineer's Response labels Aug 25, 2021
@google-ml-butler
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you.

@sgowroji sgowroji added stat:awaiting googler Waiting for Google Engineer's Response and removed stat:awaiting response Waiting for user response stale labels Sep 1, 2021
@sgowroji
Copy link

Hi @FladioArmandika, Were you able to load the wasm.js files as mentioned in the above comment. Thanks!

@sgowroji sgowroji removed the stat:awaiting googler Waiting for Google Engineer's Response label Sep 15, 2021
@sgowroji sgowroji added the stat:awaiting response Waiting for user response label Sep 15, 2021
@google-ml-butler
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you.

@google-ml-butler
Copy link

Closing as stale. Please reopen if you'd like to work on this further.

@google-ml-butler
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

@sgowroji sgowroji removed stat:awaiting response Waiting for user response stale labels Sep 29, 2021
@nandwalritik
Copy link

I am getting the same issue with the pose, has anyone found any solution for it?

@nihirv
Copy link

nihirv commented Mar 8, 2022

Having this issue with face_mesh

@Jonathan-J8
Copy link

Jonathan-J8 commented Aug 24, 2022

I've the same issue with face_mesh (version ^0.4.1633559619)
I use sveltekit. It log this warning :

@mediapipe/face_mesh doesn't appear to be written in CJS, but also doesn't appear to be a valid ES module (i.e. it doesn't have "type": "module" or an .mjs extension for the entry point). Please contact the package author to fix.

In dev mode all things work but in production this appear :

Uncaught (in promise) TypeError: Ip.FaceMesh is not a constructor

Maybe all of this come from the fact that the source code is an IIFE.
The only way I did succed to use it in production was to add the script globally as in the exemple
https://google.github.io/mediapipe/solutions/face_mesh.html

@positlabs
Copy link

It's great that the types are included in the package, but it required a lot of troubleshooting and a weird workaround to get them to actually work. The window props are perfectly functional, but if I try to import the equivalent values, I get errors like "undefined is not a function" or "Holistic is not a constructor" even though the types say it should be fine. The workaround is to grab the functional window props and reassign the types manually.

// load window scoped stuff that actually works
import '@mediapipe/holistic/holistic'
import '@mediapipe/drawing_utils'

// load types and function signatures
import {
  drawConnectors as mpDrawConnectors, 
  drawLandmarks as mpDrawLandmarks,
  LandmarkConnectionArray
} from '@mediapipe/drawing_utils'
import {
  Results as MPResults,
  Holistic as MPHolistic 
} from '@mediapipe/holistic/holistic'

// assign types to window props
const win = window as any
const MPHolistic = win.Holistic as MPHolistic
const drawConnectors = win.drawConnectors as typeof mpDrawConnectors
const drawLandmarks = win.drawLandmarks as typeof mpDrawLandmarks
const HAND_CONNECTIONS = win.HAND_CONNECTIONS as LandmarkConnectionArray
const POSE_CONNECTIONS = win.POSE_CONNECTIONS as LandmarkConnectionArray
const FACEMESH_TESSELATION = win.FACEMESH_TESSELATION as LandmarkConnectionArray

@DaveSeidman
Copy link

I experienced the same thing where it works fine in Vite's dev server but not after building for both hands and camera_utils. Using this as a workaround:

import { Hands as _Hands } from '@mediapipe/hands';
const Hands = _Hands || window.Hands;
const hands = new Hands({ locateFile: (file) => { `https://cdn.jsdelivr.net/npm/@mediapipe/hands/${file}` });

Might have something to do with the package.json referencing "main": "hands.js" which contains no actual exports statements. index.d.tsseems to have the exports but I'm not familiar with how that works.

And, unrelated to this issue, I'd prefer if the library somehow made these files available and remove the dependance on a CDN, but maybe that violates the license?

hand_landmark_full.tflite
hands_solution_packed_assets_loader.js
hands_solution_simd_wasm_bin.js
hands.binarypb
hands_solution_packed_assets.data
hands_solution_simd_wasm_bin.wasm

@MadeWithStone
Copy link

You can use the updated @mediapipe/tasks-vision api which works properly in vite locally and in production. Over at Kinetix ML we have it working locally with vite and in production with vercel deploy after facing similar issues with the face landmarks api. You can checkout our implementation here https://github.com/Kinetix-ML/kml-pipe-ts/blob/main/src/operations/faceMeshDetect.ts

@sduoooh
Copy link

sduoooh commented Oct 17, 2024

I experienced the same thing where it works fine in Vite's dev server but not after building for both hands and camera_utils. Using this as a workaround:我遇到了同样的事情,它在 Vite 的开发服务器中运行良好,但在为双手和camera_utils构建后就没有了。使用此解决方法:

import { Hands as _Hands } from '@mediapipe/hands';
const Hands = _Hands || window.Hands;
const hands = new Hands({ locateFile: (file) => { `https://cdn.jsdelivr.net/npm/@mediapipe/hands/${file}` });

Might have something to do with the package.json referencing "main": "hands.js" which contains no actual exports statements. index.d.tsseems to have the exports but I'm not familiar with how that works.可能与引用 “main”: “hands.js” 的package.json有关,该 不包含实际的 exports 语句。index.d.ts似乎有导出功能,但我不熟悉它是如何工作的。

And, unrelated to this issue, I'd prefer if the library somehow made these files available and remove the dependance on a CDN, but maybe that violates the license?而且,与此问题无关,我更愿意图书馆以某种方式提供这些文件并消除对 CDN 的依赖,但也许这违反了许可证?

hand_landmark_full.tflite
hands_solution_packed_assets_loader.js
hands_solution_simd_wasm_bin.js
hands.binarypb
hands_solution_packed_assets.data
hands_solution_simd_wasm_bin.wasm

Thanks! It works on my case.

I use Vue with Vite. Works well on dev but got '"Hands" is not a constructor' on preview after build.
When I edit my vite.config.js file like this:

import vue from '@vitejs/plugin-vue'

export default defineConfig({
  plugins: [vue()],
  build: {
    commonjsOptions: { include: [] },
  },
  optimizeDeps: {
    disabled: false,
  },
});

It put the error '"Hands" is not exported by hand.js'.
So I agree your opinion, the question maybe is the packing of that lib.

By the way, there has a same issue on Vite: same issue on Vite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy:face detection Issues related to Face Detection platform:javascript MediaPipe Javascript issues type:support General questions
Projects
None yet
Development

No branches or pull requests