question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Second argument of postMessage is not a transfert list

See original GitHub issue

Do you want to request a feature or report a bug?

A bug.

What is the current behavior?

There is an error (only in webpack-dev-server, not in regular webpack builds) in the console when there is a target “webworker”.

Chrome error:

Uncaught TypeError: Failed to execute ‘postMessage’ on ‘DedicatedWorkerGlobalScope’: The 2nd argument is neither an array, nor does it have indexed properties.

Firefox error:

TypeError: Argument 2 of DedicatedWorkerGlobalScope.postMessage can’t be converted to a sequence.

If the current behavior is a bug, please provide the steps to reproduce.

Testcase to reproduce it: https://github.com/wildpeaks/issue-webpack-dev-server-postmessage

They seem to point to this line as it appears "*" is not a valid transfert list.

What is the expected behavior?

The expected behavior is no error shown in the console.

Please mention your webpack and Operating System version.

  • Node 7.4.0
  • Windows 10
  • Webpack 2.2.0-rc.7
  • Webpack-dev-server 2.2.0-rc.0

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

8reactions
opavadercommented, Mar 7, 2017

@SEAPUNK a temporary workaround for typescript is to reassign the postMessage method to another and use that. e.g. below

const sendMessage: any = self.postMessage;

onmessage = function(this: Window, data: MessageEvent)  {
    console.log(data);
    sendMessage('got it!');
};
0reactions
mohyeidcommented, Nov 8, 2017

@hccde Thump up tp @SEAPUNK for the workaround, but yes absolutley its not working. It might be a typescript issue. I am not sure yet if its a web-pack issue, but to repro I used the below example and ran it in Angular project, which is using web-pack and it failed with the same issue https://github.com/zlepper/typescript-webworker

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript Postmessage fails with one argument, and two
If you are using window.postMessage, then you have to pass 2 or 3 parameters. window.postMessage(data, origin, [transfer]).
Read more >
Worker.postMessage() - Web APIs | MDN
The postMessage() method of the Worker interface sends a message to the worker's inner scope. This accepts a single parameter, ...
Read more >
postMessage(): common issues and how you can mitigate ...
The arguments passed to window.postMessage () (that is, the “message”) are exposed to the receiving window through the event object. Syntax: The ...
Read more >
Window.postMessage is not working in lightning experience ...
window.postMessage takes a second argument for the targetOrigin . From MDN. targetOrigin Specifies what the origin of targetWindow must be ...
Read more >
10 Web workers - HTML Standard - WhatWG
To send ArrayBuffer objects efficiently (by transferring them rather than cloning them), list them in an array in the second argument. worker ....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found