diff --git a/crates/cli-support/src/js.rs b/crates/cli-support/src/js.rs index dd3286895..caab3ed2f 100644 --- a/crates/cli-support/src/js.rs +++ b/crates/cli-support/src/js.rs @@ -642,8 +642,9 @@ impl<'a> Context<'a> { ")); } else if !self.config.browser { self.globals.push_str(&format!(" - if (typeof window === 'undefined') - var TextEncoder = require('util').TextEncoder; + const TextEncoder = typeof window === 'object' && window.TextEncoder + ? window.TextEncoder + : require('util').TextEncoder; ")); } self.globals.push_str(&format!(" @@ -667,8 +668,9 @@ impl<'a> Context<'a> { ")); } else if !self.config.browser { self.globals.push_str(&format!(" - if (typeof window === 'undefined') - var TextDecoder = require('util').TextDecoder; + const TextDecoder = typeof window === 'object' && window.TextDecoder + ? window.TextDecoder + : require('util').TextDecoder; ")); } self.globals.push_str(&format!("