Skip to content

Commit 79b419f

Browse files
authored
Check process.env exists
Some build systems or other sometimes add `window.process` in browser but not always add `window.process.env`. For example, a project created with Nuxt3 will crash due to this problem. Please check `process.env` exists or not.
1 parent b041a96 commit 79b419f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/utils/utf8.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { UINT32_MAX } from "./int";
22

33
const TEXT_ENCODING_AVAILABLE =
4-
(typeof process === "undefined" || process.env["TEXT_ENCODING"] !== "never") &&
4+
(typeof process === "undefined" || process.env === undefined || process.env["TEXT_ENCODING"] !== "never") &&
55
typeof TextEncoder !== "undefined" &&
66
typeof TextDecoder !== "undefined";
77

@@ -91,7 +91,7 @@ export function utf8EncodeJs(str: string, output: Uint8Array, outputOffset: numb
9191
const sharedTextEncoder = TEXT_ENCODING_AVAILABLE ? new TextEncoder() : undefined;
9292
export const TEXT_ENCODER_THRESHOLD = !TEXT_ENCODING_AVAILABLE
9393
? UINT32_MAX
94-
: typeof process !== "undefined" && process.env["TEXT_ENCODING"] !== "force"
94+
: typeof process !== "undefined" && process.env !== undefined && process.env["TEXT_ENCODING"] !== "force"
9595
? 200
9696
: 0;
9797

@@ -159,7 +159,7 @@ export function utf8DecodeJs(bytes: Uint8Array, inputOffset: number, byteLength:
159159
const sharedTextDecoder = TEXT_ENCODING_AVAILABLE ? new TextDecoder() : null;
160160
export const TEXT_DECODER_THRESHOLD = !TEXT_ENCODING_AVAILABLE
161161
? UINT32_MAX
162-
: typeof process !== "undefined" && process.env["TEXT_DECODER"] !== "force"
162+
: typeof process !== "undefined" && process.env !== undefined && process.env["TEXT_DECODER"] !== "force"
163163
? 200
164164
: 0;
165165

0 commit comments

Comments
 (0)