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

172
Vistas
Uncaught TypeError: worker.postMessage is not a function

I'm trying to implement a function using a worker. The source code is as follows, but I received an error message saying, "Uncaught Type Error: worker.postMessage is not a function." What should I do?

I am working on react.

someModule.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.
      ...
    }
  }
})

process.worker.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,
          ...
        });
      };
    }
  }
}

The original codes of the above two can be found in the link below. https://github.com/yoannck/WebM-MP3

config-overrides.js (at root)

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;
};

The full source code of 'config-overrides.js' can be seen here. https://github.com/facebook/create-react-app/issues/1277#issuecomment-313950613

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