Skip to content

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

Open
xianjianlf2 wants to merge 4 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 4 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.

@github-project-automation github-project-automation Bot moved this to Discussion Ongoing in PR Backlog Jul 24, 2026
@changeset-bot

changeset-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fad9c53

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

This PR includes changesets to release 28 packages
Name Type
effect Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue 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/docgen Patch
@effect/openapi-generator 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.

@github-project-automation github-project-automation Bot moved this from Discussion Ongoing to Waiting on Author in PR Backlog Jul 24, 2026
@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.

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

Status: Waiting on Author

Development

Successfully merging this pull request may close these issues.

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

2 participants