#Third-Party Library Uses `window` not `globalThis` Causing Issues.

1 messages · Page 1 of 1 (latest)

solid steeple
#

I'm using a third-party library that just released a new version and when I try to use it I get an error: error: Uncaught (in promise) ReferenceError: window is not defined
With further information

    info: window global is not available in Deno 2.
    hint: Replace `window` with `globalThis`.

This makes sense but is frustrating as I don't control that code and it makes sense they wouldn't reference globalThis as that isn't the standard. Is there a slick option of how to fix this on the fly or do I need to take their code and replace all window references with globalThis

flat wadi
#

you could try doing this before importing the third party library:

globalThis.window = globalThis
sage sun
solid steeple
#

I was unaware. Very interesting. Unfortunately globalThis.window = globalThis did not work. 😞 With it being standard maybe I'll ping the library maintainer to see if they can change, in the meantime I'll try the patch feature.

final turret
#

@solid steeple To have the code globalThis.widow = globalThis execute before the import, you actually have to move it into a seperate file that you import before the library import

#

So for example:

import "./add_window.ts";
import "the-library-that-uses-window";

and then in add_window.ts you do globalThis.window = globalThis;.