Unverified Commit edb5060f authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Fix process.env overriden in web runtime (#31261)

Fixes #31258

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
parent fd959354
......@@ -1337,8 +1337,10 @@ export default async function getBaseWebpackConfig(
// Makes sure `Buffer` and `process` are polyfilled in client and flight bundles (same behavior as webpack 4)
targetWeb &&
new webpack.ProvidePlugin({
// Buffer is used by getInlineScriptSource
Buffer: [require.resolve('buffer'), 'Buffer'],
process: [require.resolve('process')],
// Avoid process being overridden when in web run time
...(!isServer && { process: [require.resolve('process')] }),
}),
new webpack.DefinePlugin({
...Object.keys(process.env).reduce(
......
ENV_VAR_TEST="env_var_test"
\ No newline at end of file
import Foo from '../components/foo.client'
const envVar = process.env.ENV_VAR_TEST
export default function Index() {
return (
<div>
<h1>{`thisistheindexpage.server`}</h1>
<div>{envVar}</div>
<div>
<Foo />
</div>
</div>
)
}
......@@ -224,6 +224,7 @@ async function runBasicTests(context) {
)
expect(homeHTML).toContain('thisistheindexpage.server')
expect(homeHTML).toContain('env_var_test')
expect(homeHTML).toContain('foo.client')
expect(dynamicRouteHTML1).toContain('[pid]')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment