"this" should reference the window object
See original GitHub issueThis a 🐛 bug report.
“this” within imported scripts references an empty object rather than the window object.
🎛 Configuration
parcel index.html
(That’s it! That’s why I love parcel!!! 😃)
🤔 Expected Behavior
The window object should be available as “this” to scripts imported via the script tag.
😯 Current Behavior
“this” references an empty object instead.
💁 Possible Solution
I haven’t had a chance to go through the source code, but I imagine that imported code is being run within with a context somewhere. We’re passing in “{}” as the context where we should pass in the window object.
Alternatively, we might pass in a parcel-specific attribute to HTML tags that would direct parcel not to run code in a different context, but execute it untouched?
<script parcel-untouched src="./external-script"></script>
🔦 Context
I’m developing packages with rollup. Creating modules that attach themselves to the window object appears to need “this” to reference the window.
This might be consider an issue with rollup, or maybe even just my configuration, but it seems entirely legitimate to develop other libraries in this way.
💻 Code Sample
external-script.js
console.log(this);
index.html (partial)
<script src="./external-script.js"></script>
<!-- logs "{}" -->
<script>
console.log(this);
</script>
<!-- logs window object as expected-->
🌍 Your Environment
| Software | Version(s) |
|---|---|
| Parcel | 1.6.1 |
| Node | 9.5.0 |
| npm/Yarn | npm 5.6.0 |
| Operating System | Mac 10.13.3 |
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (3 by maintainers)

Top Related StackOverflow Question
I don’t know if that would be correct, some sources:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.