fix(webpack): ensure safe process.env fallback replacement#34464
Merged
Coly010 merged 1 commit intonrwl:masterfrom Feb 23, 2026
Merged
fix(webpack): ensure safe process.env fallback replacement#34464Coly010 merged 1 commit intonrwl:masterfrom
process.env fallback replacement#34464Coly010 merged 1 commit intonrwl:masterfrom
Conversation
✅ Deploy Preview for nx-docs canceled.
|
✅ Deploy Preview for nx-dev canceled.
|
Contributor
| View your CI Pipeline Execution ↗ for commit d138326
☁️ Nx Cloud last updated this comment at |
Coly010 approved these changes Feb 23, 2026
FrozenPandaz pushed a commit that referenced this pull request Feb 26, 2026
PR #30826 introduced a fallback definition for `process.env`: ```ts { 'process.env': '{}' } ``` Since `DefinePlugin` performs raw textual replacement, this can generate invalid JavaScript when user code accesses environment variables via dot notation: ```ts process.env.SOME_KEY ``` becomes: ```js {}.SOME_KEY ``` `{}` is parsed as a block statement (not an object literal), resulting in: > Unexpected token: punc (.) This PR updates the fallback to a parenthesized object literal: ```ts { 'process.env': '({})' } ``` which produces valid output: ```js ({}).SOME_KEY ``` This preserves the intended bundle-size optimization while ensuring syntactically correct output for standard `process.env.X` access patterns. ## Related Issue(s) Refs #30826 Fixes #34460 //CC @Coly010 @coolassassin (cherry picked from commit 7351e21)
FrozenPandaz pushed a commit that referenced this pull request Feb 26, 2026
PR #30826 introduced a fallback definition for `process.env`: ```ts { 'process.env': '{}' } ``` Since `DefinePlugin` performs raw textual replacement, this can generate invalid JavaScript when user code accesses environment variables via dot notation: ```ts process.env.SOME_KEY ``` becomes: ```js {}.SOME_KEY ``` `{}` is parsed as a block statement (not an object literal), resulting in: > Unexpected token: punc (.) This PR updates the fallback to a parenthesized object literal: ```ts { 'process.env': '({})' } ``` which produces valid output: ```js ({}).SOME_KEY ``` This preserves the intended bundle-size optimization while ensuring syntactically correct output for standard `process.env.X` access patterns. ## Related Issue(s) Refs #30826 Fixes #34460 //CC @Coly010 @coolassassin (cherry picked from commit 7351e21)
Contributor
| This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR #30826 introduced a fallback definition for
process.env:Since
DefinePluginperforms raw textual replacement, this can generate invalid JavaScript when user code accesses environment variables via dot notation:becomes:
{}is parsed as a block statement (not an object literal), resulting in:This PR updates the fallback to a parenthesized object literal:
which produces valid output:
This preserves the intended bundle-size optimization while ensuring syntactically correct output for standard
process.env.Xaccess patterns.Related Issue(s)
Refs #30826
Fixes #34460
//CC @Coly010 @coolassassin