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

309
Views
¿Importación relativa del módulo CJS de un trabajador evaluado en el nodo?

Estoy creando un trabajador a partir de una cadena de origen así:

 import { Worker } from "worker_threads" const w = new Worker(mySourceCode, {eval: true})

Esto funciona bien en la mayoría de los casos.

Sin embargo, supongamos que tengo un módulo CommonJS (ESM no es compatible con los trabajadores evaluados) que quiero importar al ámbito del trabajador. Dado que el trabajador no tiene un archivo fuente en el disco, no se me ocurre ninguna forma de hacer que funcione una importación relativa. Este es el mensaje de error que recibo si intento realizar una importación relativa desde la ruta del archivo fuente del subproceso principal:

 node:internal/event_target:916 process.nextTick(() => { throw err; }); ^ node:internal/modules/cjs/loader:936 throw err; ^ Error: Cannot find module './c.js' Require stack: - /mnt/c/ME/[worker eval] at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15) at Function.Module._load (node:internal/modules/cjs/loader:778:27) at Module.require (node:internal/modules/cjs/loader:999:19) at require (node:internal/modules/cjs/helpers:102:18) at [worker eval]:3:20 at Script.runInThisContext (node:vm:129:12) at Object.runInThisContext (node:vm:305:38) at node:internal/process/execution:76:19 at [worker eval]-wrapper:6:22 at evalScript (node:internal/process/execution:75:60) Emitted 'error' event on Worker instance at: at Worker.[kOnErrorMessage] (node:internal/worker:289:10) at Worker.[kOnMessage] (node:internal/worker:300:37) at MessagePort.<anonymous> (node:internal/worker:201:57) at MessagePort.[nodejs.internal.kHybridDispatch] (node:internal/event_target:647:20) at MessagePort.exports.emitMessage (node:internal/per_context/messageport:23:28) { code: 'MODULE_NOT_FOUND', requireStack: [ '/mnt/c/Users/ME/[worker eval]' ] } Node.js v17.5.0

¿Cómo puedo importar un módulo relativo de un trabajador?

about 4 years ago · Juan Pablo Isaza
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!