Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

171
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda