tfjs: SelfieSegmentation is not a constructor

Hi, Using vuejs3+vite+ts I am getting this error Uncaught (in promise) TypeError: jle.SelfieSegmentation is not a constructor

Screenshot (230)

There was a discussion here https://github.com/vitejs/vite/issues/4680

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 16 (2 by maintainers)

Most upvoted comments

I found the solution and I am putting it here just as a reference for any one who crosses path here.

function mediapipe_workaround() {
  return {
    name: 'mediapipe_workaround',
    load(id: string) {
      if (basename(id) === 'selfie_segmentation.js') {
        let code = fs.readFileSync(id, 'utf-8');
        code += 'exports.SelfieSegmentation = SelfieSegmentation;';
        return { code };
      } else {
        return null;
      }
    },
  };
}

vite.config

...
    build: {
      rollupOptions: {
        plugins: [mediapipe_workaround()],
      },
    }

@Exlord your workaround work for me , can we use in production build

Yes, this is a build time enchantment, its perfectly safe for production, I am using it in production.

Hi, @Exlord

I apologize for the delayed response. After reviewing the issue mentioned in @Bersaelor comment, it appears that the issue is with the MediaPipe package. Please refer to this comment for more details. I would recommend posting this issue in the MediaPipe repo so that the MediaPipe team can address it,please feel free to close this issue.

If Am I missing something here please let me know ? Thank you!