Skip to content

fix(webpack): ensure safe process.env fallback replacement#34464

Merged
Coly010 merged 1 commit intonrwl:masterfrom
mathiasschopmans:fix/34460-env-fallback
Feb 23, 2026
Merged

fix(webpack): ensure safe process.env fallback replacement#34464
Coly010 merged 1 commit intonrwl:masterfrom
mathiasschopmans:fix/34460-env-fallback

Conversation

@mathiasschopmans
Copy link
Contributor

PR #30826 introduced a fallback definition for process.env:

{ 'process.env': '{}' }

Since DefinePlugin performs raw textual replacement, this can generate invalid JavaScript when user code accesses environment variables via dot notation:

process.env.SOME_KEY

becomes:

{}.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:

{ 'process.env': '({})' }

which produces valid output:

({}).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

@netlify
Copy link

netlify bot commented Feb 16, 2026

Deploy Preview for nx-docs canceled.

Name Link
🔨 Latest commit d138326
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/69930e4200ed4400082871ca
@netlify
Copy link

netlify bot commented Feb 16, 2026

Deploy Preview for nx-dev canceled.

Name Link
🔨 Latest commit d138326
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/69930e42698df30008d3e820
@nx-cloud
Copy link
Contributor

nx-cloud bot commented Feb 23, 2026

View your CI Pipeline Execution ↗ for commit d138326

Command Status Duration Result
nx affected --targets=lint,test,test-kt,build,e... ✅ Succeeded 1h 10m 51s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 3m 50s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 7s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-02-23 15:56:18 UTC

@Coly010 Coly010 merged commit 7351e21 into nrwl:master Feb 23, 2026
16 of 17 checks passed
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)
@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

2 participants