Skip to content

fix: only load dotenv in explicit development mode#121

Merged
freema merged 1 commit intofreema:mainfrom
translunar:fix/dotenv-stderr-warning
Apr 15, 2026
Merged

fix: only load dotenv in explicit development mode#121
freema merged 1 commit intofreema:mainfrom
translunar:fix/dotenv-stderr-warning

Conversation

@translunar
Copy link
Copy Markdown
Contributor

Summary

  • The dotenv import guard used NODE_ENV !== 'production', which caused dotenv to load in any non-production environment — including when running as an MCP stdio server where NODE_ENV is typically unset
  • In the bundled ESM output, the dynamic import('dotenv') produced stderr warnings (e.g., require not supported in ESM) that interfered with JSON-RPC communication over stdio, causing MCP clients like Claude Code to fail to connect
  • Changed the condition to NODE_ENV === 'development' so dotenv only loads when explicitly opted in

Test plan

  • Added tests/unit/dotenv-loading.test.ts with 4 cases covering NODE_ENV unset, production, test, and development
  • Tests verified RED against the original code (2 failures), GREEN after the fix
  • Full test suite passes (223 tests, 0 failures)
  • Confirmed fix resolves MCP stdio connection failures in Claude Code

🤖 Generated with Claude Code

The dotenv import guard used `NODE_ENV !== 'production'`, which caused
dotenv to load in any non-production environment — including when running
as an MCP stdio server (where NODE_ENV is typically unset). In the
bundled ESM output, this produced stderr warnings that interfered with
JSON-RPC communication over stdio, causing MCP clients to fail to
connect.

Change the condition to `NODE_ENV === 'development'` so dotenv only
loads when explicitly opted in. Adds regression tests verifying dotenv
behavior across NODE_ENV values.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@freema freema merged commit 8586b10 into freema:main Apr 15, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants