Skip to content

fix(db): use ESM-compatible __dirname pattern in drizzle.config.ts#166

Open
bbornino wants to merge 1 commit into
playfulprogramming:mainfrom
bbornino:fix/drizzle-push-cwd-windows
Open

fix(db): use ESM-compatible __dirname pattern in drizzle.config.ts#166
bbornino wants to merge 1 commit into
playfulprogramming:mainfrom
bbornino:fix/drizzle-push-cwd-windows

Conversation

@bbornino

@bbornino bbornino commented Jun 9, 2026

Copy link
Copy Markdown

Problem: drizzle.config.ts used __dirname which doesn't exist in ESM modules (package.json has "type": "module"), causing dotenv to load 0 env vars when invoked via NX. It also imported from path/win32 instead of the cross-platform path.
Fix: Replace __dirname with the canonical ESM pattern using fileURLToPath(import.meta.url) and dirname. Change path/win32 import to path.

Summary by CodeRabbit

  • Chores
    • Updated database configuration environment file resolution for improved reliability and consistency across different module loading scenarios.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2963fdbc-8640-4ed9-a0dd-85ea31487877

📥 Commits

Reviewing files that changed from the base of the PR and between c42a05b and cbff8d3.

📒 Files selected for processing (1)
  • packages/db/drizzle.config.ts

📝 Walkthrough

Walkthrough

Drizzle configuration file now resolves the .env path dynamically from the current module location using Node's ESM utilities (fileURLToPath, dirname, resolve) instead of relying on a hardcoded relative path. The computed absolute path is passed to dotenv.config for reliable environment variable loading.

Changes

Environment path resolution

Layer / File(s) Summary
ESM-based .env path resolution
packages/db/drizzle.config.ts
Node ESM utilities (fileURLToPath, dirname, resolve) compute __dirname from import.meta.url and construct an absolute .env path, replacing the hardcoded relative path passed to dotenv.config.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately and specifically describes the main change: fixing ESM compatibility in drizzle.config.ts by adopting the proper __dirname pattern for ES modules.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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.

1 participant