Incorrect handling of `this` (should refer to `window`).
rattrayalex opened this issue · 6 comments
Hi,
Thanks for all your hard work. Some legacy scripts I'm trying to load use this
to refer to window
, eg; this.jQuery
when a window-loaded jQuery is provided. However, I'm getting an uncaught TypeError
, claiming this
is undefined.
Note that I'm using the devtool eval-source-map
, in case that could be related.
Thanks!
I should add that using imports?this=>window
also wasn't working.
I'm trying to introduce webpack into a legacy app and this seemed like an easy way to get immediate implementation with equivalent functionality until I ran into this issue. A third party plugin is implicitly declaring a function (onto window) and as stated, it doesn't work.
The official docs, as sparse as they are, mention that this plugin
evaluates code in the global context, just like you would add the code into a script tag.
Which is incorrect, there is a difference and it breaks code.
I'm encountering the same issue here. this
is undefined
. window
is defined correctly though. As a result of this
not being set to window
, a lot of older libraries break. Anybody know of a way around this that doesn't include me updating all my libraries to reference window
instead?
Hi. I got same issue. It's caused by strict mode appended to script by webpack import system. In strict mode context is not implicitly added to globals. I'm afraid script loader has nothing to do with this.
@clixr How did you solve it?
See webpack/webpack#2512 for how to avoid adding 'use strict'