Search code examples
javascriptfrontendrollupjssveltesapper

Sapper keep getting warning from client about 'this' keyword?


Keep getting this warning from the client, but not entirely sure what could be causing it. Any guidance in the right direction would be very helpful!

• client
The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
1: var __extends = (this && this.__extends) || (function () {
                    ^
2:     var extendStatics = function (d, b) {
3:         extendStatics = Object.setPrototypeOf ||
The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
1: var __extends = (this && this.__extends) || (function () {
                            ^
2:     var extendStatics = function (d, b) {
3:         extendStatics = Object.setPrototypeOf ||
The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
1: var __assign = (this && this.__assign) || function () {
                   ^
2:     __assign = Object.assign || function(t) {
3:         for (var s, i = 1, n = arguments.length; i < n; i++) {
The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
1: var __assign = (this && this.__assign) || function () {
                           ^
2:     __assign = Object.assign || function(t) {
3:         for (var s, i = 1, n = arguments.length; i < n; i++) {

Solution

  • I was able to solve this problem by adding the following code to my client rollup bundle.

    context: "window"

    Here is the documentation related to this error: https://rollupjs.org/guide/en/#error-this-is-undefined