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

241
Views
TypeError no detectado: worker.postMessage no es una función (js)

Estoy tratando de implementar una función usando un trabajador. El código fuente es el siguiente, pero recibí un mensaje de error que decía: "Error de tipo no detectado: worker.postMessage no es una función". ¿Qué tengo que hacer?

Estoy trabajando en reaccionar.

algúnModulo.js

 import WorkerScript from './process.worker.js'; var SomeModule = (function() { if (window.Worker) { let worker = new WorkerScript(); worker.onmessage = (event) => { console.log(event.data); } const someFunction = function(blob, decomposition = false) { worker.postMessage({ init : true }); //The part where an error occurs. ... } } })

proceso.trabajador.js

 export default class WorkerScript { constructor() { console.log("Worker Enabled."); ... if ("function" === typeof importScripts) { importScripts("Mp3LameEncoder.min.js"); } ... onmessage = (event) => { if (event.data.init) { index = 0; } else { Promise.resolve(event.data).then(convert()); } }; // Buffer needs two channels function convert() { index++; return (buffer) => { ... postMessage({ index: buffer.step, ... }); }; } } }

Los códigos originales de los dos anteriores se pueden encontrar en el siguiente enlace. https://github.com/yoannck/WebM-MP3

config-overrides.js (en la raíz)

 const lodashCloneDeep = require('lodash/cloneDeep'); module.exports = function override(config, env) { // Add worker-loader by hijacking configuration for regular .js files. const workerExtension = /\.worker\.js$/; ... return config; };

El código fuente completo de 'config-overrides.js' se puede ver aquí. https://github.com/facebook/create-react-app/issues/1277#issuecomment-313950613

Si imprimo el worker en la consola, ¡es el siguiente! ibb.co/JKQV8rq

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!