@@ -30,15 +30,23 @@ export function definePlugin(config: ResolvedConfig): Plugin {
30
30
} )
31
31
}
32
32
33
- const processEnv = {
34
- 'process.env.' : `({}).` ,
35
- 'global.process.env.' : `({}).` ,
36
- 'globalThis.process.env.' : `({}).`
37
- }
38
-
39
33
function generatePattern (
40
34
ssr : boolean
41
35
) : [ Record < string , string | undefined > , RegExp ] {
36
+ const processEnv = ssr
37
+ ? {
38
+ // account for non-node environments like v8
39
+ 'process.env.' : `(typeof process === 'undefined' ? {} : process.env).` ,
40
+ 'global.process.env.' : `(typeof global.process === 'undefined' ? {} : global.process.env).` ,
41
+ 'globalThis.process.env.' : `(typeof globalThis.process === 'undefined' ? {} : globalThis.process.env).`
42
+ }
43
+ : {
44
+ // client never has process
45
+ 'process.env.' : `({}).` ,
46
+ 'global.process.env.' : `({}).` ,
47
+ 'globalThis.process.env.' : `({}).`
48
+ }
49
+
42
50
const replacements : Record < string , string | undefined > = {
43
51
'process.env.NODE_ENV' : JSON . stringify (
44
52
process . env . NODE_ENV || config . mode
@@ -51,7 +59,7 @@ export function definePlugin(config: ResolvedConfig): Plugin {
51
59
) ,
52
60
...userDefine ,
53
61
...importMetaKeys ,
54
- ...( ssr ? { } : processEnv )
62
+ ...processEnv
55
63
}
56
64
57
65
const pattern = new RegExp (
0 commit comments