DenoDDeno
Powered by
teleclimberT
Denoβ€’14mo agoβ€’
7 replies
teleclimber

How to initialize global variable so it can be accessed without globalThis?

I'm hacking on a large existing codebase using Deno. This codebase uses a number of global variables like this:

if( __DEV__ && ... ) 
if( __DEV__ && ... ) 


Their build system sets these values at build time I think. I am trying to hack around without building, but I am stuck because I haven't figured out how to initialize these variables globally. I always get an error of "ReferenceError DEV is not defined".

The code I'm working with uses ESM modules and TypeScript. There is a global.d.ts that sets

declare var __DEV__: boolean
declare var __DEV__: boolean


I include this global.d.ts via deno.json:

"compilerOptions": {
        "types": [
            "./global.d.ts"
        ]
    },
"compilerOptions": {
        "types": [
            "./global.d.ts"
        ]
    },


This makes the TS side of things happy. But I still don't know how to actually initialize that value. I tried globalThis, window, and just DEV = true;

Any help would be appreciated, thanks!
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,934Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

globalThis missing dispatchEvent
naxNnax / help
3mo ago
`await import()` without global execution
MrKleeblattMMrKleeblatt / help
3y ago
Deno showing node globalThis error
Ren HiyamaRRen Hiyama / help
3y ago