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

[fix] error on HMR with es6 bundles #5862

merged 2 commits into from Nov 27, 2017


None yet

Slashgear commented Oct 20, 2017

What kind of change does this PR introduce?

It's a bug fix.

Did you add tests for your changes?

Update test.

If relevant, link to documentation update:



We notice a bug in webpack HMR during our spike on creating es6 bundles.


  • bootstrap dev bundle containes a this no longer bound to window, so it was undefined.


  • Use window instead of this in both scripts templates.

This bug was identifed in #5776

Does this PR introduce a breaking change?


Other information
Fix #5776
Made with @Osirisxxl


This comment has been minimized.

jsf-clabot commented Oct 20, 2017

CLA assistant check
All committers have signed the CLA.


This comment has been minimized.

webpack-bot commented Oct 20, 2017

Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon.


sokra approved these changes Oct 22, 2017

Makes sense


I don’t think you can use window inside a web worker. Getting the global inside a es6 environment is difficult unless you know something about your environment.


This comment has been minimized.


michael-ciniawsky commented Oct 24, 2017

Web Worker API

workers run in another global context that is different from the current window. This context is represented by a DedicatedWorkerGlobalScope object in the case of dedicated workers (standard workers that are utilized by a single script; shared workers use SharedWorkerGlobalScope).

You can run whatever code you like inside the worker thread, with some exceptions. For example, you can't directly manipulate the DOM from inside a worker, or use some default methods and properties of the window object.

WorkerGlobalScope.self ?


Should use self in WebWorker


This comment has been minimized.

webpack-bot commented Oct 30, 2017

@Slashgear Thanks for your update.

I labeled the Pull Request so reviewers will review it again.

@sokra Please review the new changes.


sokra approved these changes Nov 27, 2017

@sokra sokra merged commit 801a253 into webpack:master Nov 27, 2017

9 of 12 checks passed

codecov/changes/integration 1 file has unexpected coverage changes not visible in diff.
codecov/project/integration 91.9% (-0.01%) compared to 0c4d69b
coverage/coveralls Coverage decreased (-0.03%) to 93.841%
ci/circleci Your tests passed on CircleCI!
codacy/pr Good work! A positive pull request.
codecov/changes/unit No unexpected coverage changes found.
codecov/patch/integration Coverage not affected when comparing 0c4d69b...00daab2
codecov/patch/unit Coverage not affected when comparing 0c4d69b...00daab2
codecov/project/unit 49.96% (target 0%)
continuous-integration/appveyor/pr AppVeyor build succeeded
continuous-integration/travis-ci/pr The Travis CI build passed
licence/cla Contributor License Agreement is signed.

This comment has been minimized.


sokra commented Nov 27, 2017



This comment has been minimized.

liaobin312716 commented Dec 1, 2017

Hi, I got an error ReferenceError:Can't find variable:self(

  • Webpack Version: 3.9.1
    But is works when webpack version is 3.8.1.

Then , I compared the compiled bundle file with the last .
version: 3.8.1
version: 3.9.1

Use self instead of this maybe bring some new problems ?


This comment has been minimized.

jukben commented Dec 2, 2017

Hi @sokra in we use target: webworker in general because Debug JS remotely in React Native Dev tools. So we experienced the same issue as @liaobin312716 when the JS running outside of webworker (self is not defined in iOS/Andorid JS env). When developer enforce "webworker mode" (code running in webworker) for remotely debug everything is fine. Is there anything that we can do about it? Maybe there is some setting how to mock "self" if it' not present in the current environment. var self = self || window would be sufficient. 🙈

We can't change mode on demand, that would result in restarting of Webpack which is time-consuming.


This comment has been minimized.

dor-itzhaki commented on lib/JsonpMainTemplatePlugin.js in 27e4d14 Dec 12, 2017

shouldn't that be "self" as done here: 00daab2 ?


This comment has been minimized.

After this commit building of WebWorkers as others entries (webpack.entry) does not work any more in dev-mode with hot reload. Actually builds goes success but in browser i see this error 'Uncaught ReferenceError: window is not defined'
Is it possible to change 'window' to 'self' ? I try it on my local machine and looks like it's work.

This comment has been minimized.

robaweb replied Jan 30, 2018

This comment has been minimized.

pedroteixeira replied Feb 15, 2018

Are there any workarounds for this? Is this something fixed in v4?

This comment has been minimized.

pedroteixeira replied Feb 15, 2018

as workaround, is there any plugin to allow a replace on the generated file to fix this?

This comment has been minimized.

chenxeed replied Mar 20, 2018

I faced issue too on this, wish it could be fixed soon in new version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment