mediapipe: [tasks-vision] ReferenceError: self is not defined

Have I written custom code (as opposed to using a stock example script provided in MediaPipe)

No

OS Platform and Distribution

Ubuntu 22.04

Mobile device if the issue happens on mobile device

No response

Browser and version if the issue happens on browser

No response

Programming Language and version

Typescript

MediaPipe version

No response

Bazel version

No response

Solution

Pose

Android Studio, NDK, SDK versions (if issue is related to building in Android environment)

No response

Xcode & Tulsi version (if issue is related to building for iOS)

No response

Describe the actual behavior

Importing @mediapipe/tasks-vision module leads to an error

Describe the expected behaviour

Should import the module

Standalone code/steps you may have used to try to get what you need

In SvelteKit 1.20.4:

import { FilesetResolver, PoseLandmarker } from "@mediapipe/tasks-vision";

const vision = await FilesetResolver.forVisionTasks(
      "https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision/wasm"
    );

const poseLandmarker = await PoseLandmarker.createFromOptions(vision, {
            baseOptions: {
                modelAssetPath: `https://storage.googleapis.com/mediapipe-models/pose_landmarker/pose_landmarker_lite/float16/1/pose_landmarker_lite.task`,
                delegate: "GPU"
            },
            runningMode: "VIDEO",
        });

Other info / Complete Logs

7:23:29 AM [vite] Error when evaluating SSR module /src/lib/detection/video/PoseLandmarkDetector.ts: failed to import "@mediapipe/tasks-vision"
 |- ReferenceError: self is not defined
     at file:///app/node_modules/@mediapipe/tasks-vision/vision_bundle.mjs:1:7
     at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

About this issue

  • Original URL
  • State: open
  • Created 10 months ago
  • Reactions: 6
  • Comments: 22

Commits related to this issue

Most upvoted comments

0.0.0-nightly-20231024 is working and contains the fix.

We currently only support browser environments and don’t have testing infrastructure that can validate that our libraries work in Node. I will try to make this work though.

(Note that there doesn’t seem to be good support for WebGL2 in Node, so I am not sure we can offer a solution anytime soon).

Actually it seems that 0.10.8 is broken, for me — I’ll have to gather error messages to see what has happened (the impact is vision loads but doesn’t run).

I can use 0.10.6, though; the error that led me to this thread seemed to go away by itself, and I’m not sure why.

[Edit: I think I’ve figured out what I was seeing; it’s an artefact of hot module reloading, where vite is trying to run ssr on a view of the site that would never be visible on the server in production nope it also breaks builds. So there was/is a genuine bug, but I was only hitting it in development. The component it tries to load relies on browser-only functionality.]

I suspect the document is not defined error is something else, given code expecting document should run in a browser, and code expecting self has probably been designed to run in a worker, right?

I find the same issue in v10.0.7 So I am using v0.10.4 for now (as not causing this issue)

We have yet to build the testing infrastructure to ensure that our libraries work for Servers/Node. This is already in our backlog. Will hopefully get to this soon.