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

234
Vistas
¿Cómo anular o extender el módulo ESM en el nodo js?

quiero agregar una nueva función o anular la función en el módulo en el tipo esm.

Pero no sé como ???

en CommonJS es el siguiente

añadir nueva función

 // include the module that you like extend var fs = require('fs'); // add a new function, printMessage(), to the module fs.printMessage = function(str){ console.log("Message from newly added function to the module"); console.log(str); } // re-export the module for changes to take effect module.exports = fs // you may use the newly added function fs.printMessage("Success");

anular

 // include the module whose functions are to be overridden var fs = require('fs'); // delete the function you would like to override delete fs['readFile']; // add new functional with the same name as deleted function fs.readFile = function(str){ console.log("The functionality has been overridden."); console.log(str); } // re-export the module for changes to take effect module.exports = fs // you may use the newly overriden function fs.readFile("sample.txt");

pero en ESM no lo sé?

por ejemplo

prueba.mjs

 const add = (a,b) => { return a+b; } const sub = (a,b) => { return ab; } export {add,sub};

índice.js

 import * as m from './test.mjs'; now , how to add new function or override 'add' or 'sub' in test.mjs
about 4 years ago · Juan Pablo Isaza
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