Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

self.postMessage is not a function under webpack-dev-server #792

Closed
didi0613 opened this issue Feb 17, 2017 · 14 comments
Closed

self.postMessage is not a function under webpack-dev-server #792

didi0613 opened this issue Feb 17, 2017 · 14 comments

Comments

@didi0613
Copy link

didi0613 commented Feb 17, 2017

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

Bug

What is the current behavior?
screen shot 2017-02-16 at 6 27 48 pm
screen shot 2017-02-16 at 6 27 56 pm
Self is referring to a wrong object serviceworkerglobalscope instead of window.
PostMessage is not defined under serviceworkerglobalscope

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

Clone https://github.com/didi0613/electrode/tree/webpack-2.0
checkout branch webpack-2.0
npm i && npm run bootstrap
goto samples/universal-react-node app
npm install
gulp dev

What is the expected behavior?
There should be no error and pwa should work

If this is a feature request, what is motivation or use case for changing the behavior?

Please mention your webpack and Operating System version.
webpack 2.2.0
wepack-dev-server 2.2.0
os: mac

@didi0613 didi0613 changed the title self.postMessage is not a function self.postMessage is not a function under webpack-dev-server Feb 17, 2017
@dangerousdan
Copy link

Related to #745

@shellscape
Copy link
Contributor

Should be resolved in #813 and v2.7.1. If it's not, please ping me and we'll reopen.

@ddomonkos
Copy link

Hi @shellscape, I still have the error in v2.7.1. Do you have any tips how to fix this?

image

Let me know if you need more info about the error.

@shellscape
Copy link
Contributor

Unfortunately I don't. We've had a few PRs related to this and I'm unable to reproduce the issue in any of our tests. If this is still occurring there's a better than average chance that it's your configuration or environment causing it. Sidenote: If you're not on webpack@3 yet, it's time to upgrade.

@ddomonkos
Copy link

Ok thank you, I'll try to debug it some more, maybe I find something.

Btw I am using the newest webpack already.

@codelinguist
Copy link

I also had this exact issue in my angular 4 app today
This occurs when i call a function that opens a WebSocket connection and sends message when the app initializes.
I thought there's some contention happening so i moved the function call inside setTimeout with 100ms delay to give time for the webpack dev server to initialize. The error is gone!

I hope this helps.

@LeahArmstrong
Copy link

Sorry for bringing this thread back to life, but I've been dealing with this problem for a few days now on Webpack 3, and think I've narrowed it down to at least one possible solution for anyone having problems.

In my Vue project I was submitting Ajax requests from a component. In order to maintain access to update data tied to this further up in my component I used self = this to pass to my function. I missed the var definition in my markup, and Webpack's self.postMessage was trying to access my Vue data instead.

No errors were presented on compilation since self was already defined as a variable in Webpack.

@shellscape
Copy link
Contributor

@DustinArmstrong that may be something the main webpack project can assist with - perhaps a console warning or some such.

@YDJSZY
Copy link

YDJSZY commented Apr 22, 2018

I have also this problem, I don't know how to do ...

@devilsbibble
Copy link

Do you have set window.self=xxx ? Delete it .

@ereztdev
Copy link

ereztdev commented May 3, 2018

just don't use self, use that = this, or any other var that would not be self

@imam
Copy link

imam commented Aug 3, 2018

If you want to use self anywhere in your code, make sure you always redefined self at the very last line of everything (window.self = window)

@asrofie
Copy link

asrofie commented Oct 2, 2018

I have same issue, I fixed it with finding self variable and make sure it redefined (using let keyword, e.g let self = this).

@martinsJoseph007
Copy link

martinsJoseph007 commented Aug 4, 2019

Sorry for bringing this thread back to life, but I've been dealing with this problem for a few days now on Webpack 3, and think I've narrowed it down to at least one possible solution for anyone having problems.

In my Vue project I was submitting Ajax requests from a component. In order to maintain access to update data tied to this further up in my component I used self = this to pass to my function. I missed the var definition in my markup, and Webpack's self.postMessage was trying to access my Vue data instead.

No errors were presented on compilation since self was already defined as a variable in Webpack.

You are a genius.

fiedl added a commit to fiedl/your_platform that referenced this issue Jul 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests