Skip to content

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

Open
xianjianlf2 wants to merge 3 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 3 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() default environment resolution to rely on globalThis.process.env when available, removing the prior fallback that could access import.meta.env.
  • Documentation
    • Refreshed fromEnv usage notes to reflect the new default environment behavior and how to supply env in custom runtimes.
  • Tests
    • Added coverage for default environment loading and restoring process.env.
    • Added verification that an explicit env option overrides the default behavior.
    • Included 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: 94ce156

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: c9c4c2ef-2a04-42d3-b556-4ab17bdda725

📥 Commits

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

📒 Files selected for processing (1)
  • .changeset/configprovider-import-meta-env.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, .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 the changeset records a patch release.

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

Suggested labels: bug

🚥 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 and adds tests, matching issue #6358’s goal to avoid unsupported runtimes failing during analysis.
Out of Scope Changes check ✅ Passed The changes stay focused on ConfigProvider.fromEnv, its tests, and a release note; no unrelated scope appears to be introduced.

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
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