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

170
Views
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
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!