Skip to content

fix(json-provider): resolve DUMP_DIR when Turbopack strips import.met…#374

Merged
arygupt merged 1 commit into
masterfrom
fix/json-provider-turbopack-dirname
May 22, 2026
Merged

fix(json-provider): resolve DUMP_DIR when Turbopack strips import.met…#374
arygupt merged 1 commit into
masterfrom
fix/json-provider-turbopack-dirname

Conversation

@arygupt
Copy link
Copy Markdown
Collaborator

@arygupt arygupt commented May 21, 2026

fix(json-provider): resolve DUMP_DIR when Turbopack strips import.meta.dirname

Bundler removing variable that defines where dump folder lives

import.meta.dirname is undefined in workspace-package code that Next.js 16 + Turbopack bundles into server chunks, so the resolve(import.meta.dirname, '..') in getStore() threw ERR_INVALID_ARG_TYPE on every API route that touched the JSON dump path (Option A in the README). Pages rendered but every /api/v1/* call 500'd.

import.meta.url is preserved correctly by Turbopack and still points at the original source file, so fall back to dirname(fileURLToPath(import.meta.url)) when import.meta.dirname is unavailable. Behavior is identical for tsx, plain Node ESM, and vitest, where import.meta.dirname is defined and the ?? short- circuits.

No production impact: Vercel uses DATABASE_READONLY_URL, never DUMP_DIR, so getStore() is unreachable in prod.

…a.dirname

`import.meta.dirname` is undefined in workspace-package code that Next.js 16 +
Turbopack bundles into server chunks, so the `resolve(import.meta.dirname, '..')`
in getStore() threw ERR_INVALID_ARG_TYPE on every API route that touched the
JSON dump path (Option A in the README). Pages rendered but every /api/v1/* call
500'd.

`import.meta.url` is preserved correctly by Turbopack and still points at the
original source file, so fall back to `dirname(fileURLToPath(import.meta.url))`
when `import.meta.dirname` is unavailable. Behavior is identical for tsx, plain
Node ESM, and vitest, where `import.meta.dirname` is defined and the ?? short-
circuits.

No production impact: Vercel uses DATABASE_READONLY_URL, never DUMP_DIR, so
getStore() is unreachable in prod.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 21, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
inferencemax-app Ready Ready Preview, Comment May 21, 2026 11:01pm

Request Review

@claude
Copy link
Copy Markdown

claude Bot commented May 21, 2026

Claude finished @arygupt's task in 1m 2s —— View job


🟢 LGTM — no blocking issues found

The fix is correct, minimal, and well-scoped.

What I verified:

  • import.meta.dirname ?? dirname(fileURLToPath(import.meta.url)) is the standard Node ESM workaround. When import.meta.dirname is defined (Node ≥ 20.11 in tsx/Node/vitest), the ?? short-circuits and behavior is identical to before. When undefined (Turbopack server bundle), the fallback derives the same directory from import.meta.url, which Turbopack rewrites to a usable source-relative file URL.
  • Other call sites of import.meta.dirname in packages/db (migrate.ts, ingest-supplemental.ts, ingest-gcs-backup.ts) are CLI scripts executed directly via tsx/node — they don't go through Turbopack bundling, so they don't need the same fallback. The packages/app/scripts/capture-cypress-fixtures.ts script has its own separate __dirname workaround for a different reason (tsx CJS loader). Scope of this PR is correct.
  • The oxlint-disable-next-line unicorn/prefer-import-meta-properties comment uses the syntax already established in this repo (e.g. load-dump.ts, ingest-supplemental.ts) and the inline justification is clear.
  • No production impact, as stated in the PR body — Vercel uses DATABASE_READONLY_URL and never hits getStore().

No test is needed here: this is an environment-detection workaround for a bundler quirk, and it's only exercised in the local Option-A dev path that has no automated coverage today.

Todos

  • Read changed file
  • Verify the Turbopack import.meta.dirname claim and the fallback semantics
  • Check other use sites of import.meta.dirname in the repo
  • Post review
    • Branch fix/json-provider-turbopack-dirname

@arygupt arygupt merged commit 98e93a1 into master May 22, 2026
15 checks passed
@arygupt arygupt deleted the fix/json-provider-turbopack-dirname branch May 22, 2026 20:35
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