Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

272
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda