Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix process.env overriden in web runtime #31261

Merged
merged 2 commits into from Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/next/build/webpack-config.ts
Expand Up @@ -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(
Expand Down
@@ -0,0 +1 @@
ENV_VAR_TEST="env_var_test"
@@ -1,10 +1,15 @@
import Foo from '../components/foo.client'

const envVar = process.env.ENV_VAR_TEST

export default function Index() {
return (
<div>
<h1>{`thisistheindexpage.server`}</h1>
<Foo />
<div>{envVar}</div>
<div>
<Foo />
</div>
</div>
)
}
Expand Up @@ -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]')
Expand Down