Skip to content

Guard import.meta.env in ConfigProvider.fromEnv - #6570

Open
xianjianlf2 wants to merge 6 commits into
Effect-TS:mainfrom
xianjianlf2:fix/configprovider-import-meta-env-6358
Open

Guard import.meta.env in ConfigProvider.fromEnv#6570
xianjianlf2 wants to merge 6 commits into
Effect-TS:mainfrom
xianjianlf2:fix/configprovider-import-meta-env-6358

Conversation

@xianjianlf2

@xianjianlf2 xianjianlf2 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Fixes #6358

ConfigProvider.fromEnv() currently reads import.meta.env while building the default environment. Some runtimes can throw when import.meta is accessed, so this guards that lookup and falls back to process.env / an empty Vite env instead.

Tested:

  • pnpm --filter effect check
  • pnpm --filter effect exec vitest run test/ConfigProvider.test.ts -t "fromEnv" --config vitest.config.ts

Summary by CodeRabbit

  • Bug Fixes
    • Updated ConfigProvider.fromEnv() to resolve its default environment from process.env (when available) instead of using any import.meta.env fallback.
  • Documentation
    • Refreshed fromEnv guidance to match the new default behavior and clarify how to pass env in custom runtimes.
  • Tests
    • Added tests covering default environment loading, restoration of process.env, and that an explicit env option overrides the default.
    • Added a check ensuring the implementation does not reference import.meta.

@changeset-bot

changeset-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b097ad8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 30 packages
Name Type
effect Patch
@effect/ai-anthropic Patch
@effect/ai-openai Patch
@effect/ai-openai-compat Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/docgen Patch
@effect/doctest Patch
@effect/openapi-generator Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-deno Patch
@effect/platform-node Patch
@effect/platform-node-shared Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/vitest Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added the 4.0 label Jul 24, 2026
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a66623b2-de81-4243-a8fd-d992ba6794d8

📥 Commits

Reviewing files that changed from the base of the PR and between 94ce156 and fad9c53.

📒 Files selected for processing (1)
  • packages/effect/CONFIG.md

📝 Walkthrough

Walkthrough

ConfigProvider.fromEnv now defaults to globalThis?.process?.env without referencing import.meta.env. Documentation, tests, and a patch changeset cover the updated behavior.

Changes

ConfigProvider environment loading

Layer / File(s) Summary
Default environment loading and validation
packages/effect/src/ConfigProvider.ts, packages/effect/test/ConfigProvider.test.ts, packages/effect/CONFIG.md, .changeset/configprovider-import-meta-env.md
fromEnv uses process.env only by default; tests verify default loading, explicit environment overrides, and removal of import.meta, while documentation and the changeset record the updated behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: bug

Suggested reviewers: gcanti

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR removes the default import.meta.env access from ConfigProvider.fromEnv and preserves env-based configuration through process.env or explicit env input.
Out of Scope Changes check ✅ Passed The added tests, docs, and changeset all support the import.meta.env fix and do not introduce unrelated scope.

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot added the bug Something isn't working label Jul 24, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/effect/test/ConfigProvider.test.ts (1)

194-208: 🩺 Stability & Availability | 🔵 Trivial | 🏗️ Heavy lift

Add regression coverage for unsupported import.meta environments.

This test only verifies the process-environment fallback. Add a build/runtime fixture for an environment that cannot access import.meta, so the new guard is validated against the failure mode described in the PR objective.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/effect/test/ConfigProvider.test.ts` around lines 194 - 208, Add
regression coverage alongside the existing default-environment test for
ConfigProvider.fromEnv that executes it in a runtime/build fixture where
import.meta is unavailable. Assert the provider still uses process.env without
throwing, while preserving the current environment restoration and success
expectations.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/effect/test/ConfigProvider.test.ts`:
- Around line 194-208: Add regression coverage alongside the existing
default-environment test for ConfigProvider.fromEnv that executes it in a
runtime/build fixture where import.meta is unavailable. Assert the provider
still uses process.env without throwing, while preserving the current
environment restoration and success expectations.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f9c0f5be-8963-4948-848b-ea8934422b63

📥 Commits

Reviewing files that changed from the base of the PR and between 5101e92 and 555a5ca.

📒 Files selected for processing (2)
  • packages/effect/src/ConfigProvider.ts
  • packages/effect/test/ConfigProvider.test.ts

@tim-smart tim-smart left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't fix the issue as it fails during a module analysis step, not at runtime.

@xianjianlf2

Copy link
Copy Markdown
Contributor Author

Thanks, that makes sense. I updated the branch so ConfigProvider no longer touches import.meta at all, including during module analysis. The default path is now just process.env when it exists, and I also cleaned up the docs wording to match.

Local check: pnpm --dir packages/effect test ConfigProvider.test.ts --run passes.

@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
basic.ts 7.06 KB 7.06 KB 0.00 KB (0.00%)
batching.ts 9.86 KB 9.86 KB 0.00 KB (0.00%)
brand.ts 6.34 KB 6.34 KB 0.00 KB (0.00%)
cache.ts 10.71 KB 10.71 KB 0.00 KB (0.00%)
config.ts 20.72 KB 20.73 KB -0.01 KB (-0.05%)
differ.ts 20.31 KB 20.31 KB 0.00 KB (0.00%)
http-client.ts 21.53 KB 21.53 KB 0.00 KB (0.00%)
logger.ts 10.84 KB 10.84 KB 0.00 KB (0.00%)
metric.ts 8.98 KB 8.98 KB 0.00 KB (0.00%)
optic.ts 7.18 KB 7.18 KB 0.00 KB (0.00%)
pubsub.ts 14.99 KB 14.99 KB 0.00 KB (0.00%)
queue.ts 11.66 KB 11.66 KB 0.00 KB (0.00%)
schedule.ts 10.83 KB 10.83 KB 0.00 KB (0.00%)
schema-class.ts 19.27 KB 19.27 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 29.09 KB 29.09 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 25.40 KB 25.40 KB 0.00 KB (0.00%)
schema-string-transformation.ts 13.42 KB 13.42 KB 0.00 KB (0.00%)
schema-string.ts 10.95 KB 10.95 KB 0.00 KB (0.00%)
schema-template-literal.ts 15.21 KB 15.21 KB 0.00 KB (0.00%)
schema-toArbitraryLazy.ts 22.02 KB 22.02 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 24.45 KB 24.45 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 19.28 KB 19.28 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 19.11 KB 19.11 KB 0.00 KB (0.00%)
schema-toFormatter.ts 18.97 KB 18.97 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 22.69 KB 22.69 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 19.60 KB 19.60 KB 0.00 KB (0.00%)
schema.ts 18.52 KB 18.52 KB 0.00 KB (0.00%)
stm.ts 12.63 KB 12.63 KB 0.00 KB (0.00%)
stream.ts 9.80 KB 9.80 KB 0.00 KB (0.00%)

冼健聪 added 2 commits August 5, 2026 21:08
…onfigprovider-import-meta-env-6358

# Conflicts:
#	packages/effect/src/ConfigProvider.ts
@xianjianlf2

Copy link
Copy Markdown
Contributor Author

已推送 b097ad8e,同步最新 main 并保留不访问 import.meta.env 的修复;ConfigProvider 测试 99/99 通过,dprint 检查通过。@tim-smart 请复审。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0 bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ConfigProvider.fromEnv references import.meta.env in unsupported runtimes

2 participants