Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

267
Views
How to inject the @mediapipe/face_mesh module into my bundle with rollupjs

I am new to Rollup and have been learning a lot the last couple days. I am making a module with Rollup that depends on @mediapipe/face_mesh, which is provided as (I think?) an IIFE. I am interested in injecting face_mesh into my output file(s) instead of including it as an external dependency.

I am using the commonjs and node-resolve plugins to inject it -- everything is working except for one bit. I have some strange behavior with how the script is added to the output index.js

package.json

"source": "src/index.ts",
"main": "dist/index.js",
"dependencies": {
    "@mediapipe/face_mesh": "0.4.1633559619"
}

src/index.ts

import { FaceMesh } from '@mediapipe/face_mesh'

const faceMesh = new FaceMesh()

rollup.config.js

export default {
  input: 'src/index.ts',
  output: [
    {
      file: pkg.main,
      format: 'cjs'
    }
  ],
  plugins: [
    typescript({
      typescript: require('typescript')
    }),
    commonjs({
      include: /\/node_modules\//
    }),
    nodeResolve({
      browser: true
    }),
    globals(),
    builtins()
  ]
}

face_mesh.js

(function(){/*

 Copyright The Closure Library Authors.
 SPDX-License-Identifier: Apache-2.0
*/
var v;function aa(a){var b=0;return function(){
    /* a bunch of minified code */
}).call(this);

dist/index.js (rollout output)

var face_mesh = {};

(function(){/*

 Copyright The Closure Library Authors.
 SPDX-License-Identifier: Apache-2.0
*/
var v;function aa(a){var b=0;return function(){
    /* a bunch of minified code */
}).call(commonjsGlobal);

...

const faceMesh = new face_mesh.FaceMesh()

You can see that node_resolve has named the module "face_mesh" and set up an exports object for it. But commonjs I believe changes the .call(this) to .call(commonjsGlobal).

When I run this module, I get an error that FaceMesh does not exist on type face_mesh.

If I change commonjsGlobal in the output file to face_mesh, then it works. Based on the output, I think is what it ought to be, but the "this" is considered to be the global scope instead of the module.

I think I could use the replace plugin to do this change automatically as a final step, but that feels pretty hacky to me. I have been looking for a better way.

Does anyone have a tip of how to handle this issue? I have done a lot of searching, but it seems to be an uncommon problem. The structure of the module from face_mesh seems like it might be uncommon, or I am having a misunderstanding of what plugin/tool I should be using to transpile it.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!