Skip to content

fix(generate): load dart renderer via its ESM build (fixes remaining dart 500) - #9

Merged
dev-jodee merged 1 commit into
mainfrom
fix/dart-esm-load
Jul 17, 2026
Merged

fix(generate): load dart renderer via its ESM build (fixes remaining dart 500)#9
dev-jodee merged 1 commit into
mainfrom
fix/dart-esm-load

Conversation

@dev-jodee

@dev-jodee dev-jodee commented Jul 17, 2026

Copy link
Copy Markdown
Owner

Follow-up to #8

#8 stopped the total outage (typescript/umi/rust/go work again), but dart itself still 500'd on production:

Cannot find module '/var/task/node_modules/@codama/visitors-core/dist/index.node.cjs'

Why: dart's CJS build (loaded via createRequire) requires the .cjs variants of a large @codama / @solana/codecs / @noble/hashes tree. Next only bundles those packages as .mjs (the js/rust/go renderers import them via ESM), so the .cjs files aren't in the lambda.

Fix

  • Load dart's real ESM build by path, with /* webpackIgnore */ /* turbopackIgnore */ so Turbopack leaves it as a runtime import (a plain dynamic import() of a computed path throws Turbopack's "expression is too dynamic"). The ESM build reuses the already-bundled .mjs deps.
  • Broaden outputFileTracingIncludes to guarantee dart's ESM closure (@codama, @solana, @noble) is in the generate lambda.

Verification (local)

  • prettier ✓ · lint ✓ · tests 25/25 · build ✓
  • Local dart generate → 200, 12 .dart files.
  • Vercel-condition repro: hid all 139 *.node.cjs files (simulating the .mjs-only lambda) → all 5 languages, incl. dart, return 200. This is the exact failure mode from production.

Summary by CodeRabbit

  • Bug Fixes
    • Improved code generation reliability for Dart output.
    • Ensured required generation dependencies are included when running the generation endpoint.
    • Reduced the risk of missing packages in deployed or serverless environments.

#8 stopped the total outage but dart itself still 500'd: its CJS build
(loaded via createRequire) requires the .cjs variants of a large
@codama/@solana/@noble tree that Next only bundles as .mjs, so
@codama/visitors-core/dist/index.node.cjs was missing from the lambda.

Load dart's real ESM build by path instead (bundler-ignored so Turbopack
leaves it a runtime import, avoiding its "expression too dynamic" error),
which reuses the already-bundled .mjs deps. Broaden outputFileTracingIncludes
to guarantee dart's ESM closure (@codama/@solana/@noble) is present.
@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
castaway Ready Ready Preview, Comment Jul 17, 2026 4:42pm

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The Dart renderer now loads its ESM entry through a dynamically generated file URL. Next.js tracing for /api/generate now includes the renderer and additional Codama, Solana, and Noble dependency globs.

Changes

Dart renderer runtime

Layer / File(s) Summary
Dart ESM renderer loading
lib/codama-generate.ts
The Dart renderer is resolved from process.cwd() and dynamically imported from its ESM entry instead of using createRequire.
Serverless dependency tracing
next.config.ts
The /api/generate route includes tracing globs for codama-renderers-dart, @codama, @solana, and @noble packages.

Estimated code review effort: 2 (Simple) | ~10 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 title accurately describes the main change: loading the Dart renderer via its ESM build to resolve the remaining Dart 500 error.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/dart-esm-load

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.

@dev-jodee
dev-jodee merged commit 1c1e51a into main Jul 17, 2026
3 of 4 checks passed
@dev-jodee
dev-jodee deleted the fix/dart-esm-load branch July 17, 2026 16:43

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

Actionable comments posted: 1

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

Inline comments:
In `@lib/codama-generate.ts`:
- Around line 94-107: Patch codama-renderers-dart’s exports so node.import
resolves to the existing ESM entry, then simplify lib/codama-generate.ts by
replacing the hardcoded dartEntry path-based import with the normal package
import while preserving lazy loading. Remove the broad outputFileTracingIncludes
workaround in next.config.ts; both sites require changes, with Next tracing the
package’s correctly exported dependencies directly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0655d9d6-4466-4142-b197-0c9478468037

📥 Commits

Reviewing files that changed from the base of the PR and between 4f9392e and 722d06b.

📒 Files selected for processing (2)
  • lib/codama-generate.ts
  • next.config.ts

Comment thread lib/codama-generate.ts
Comment on lines +94 to +107
// codama-renderers-dart@0.4.x mispublishes its exports map: `import` points at a
// missing .mjs, and its CJS build drags in a large @codama/@solana/.cjs tree Next
// never bundles. Import the real ESM build by path (bundler-ignored so Turbopack
// leaves it as a runtime import) so it reuses the already-bundled .mjs deps the
// other renderers rely on. Lazy so any failure only affects dart.
const dartEntry = pathToFileURL(
path.join(
process.cwd(),
"node_modules/codama-renderers-dart/dist/index.node.js"
)
).href;
const { renderVisitor: renderDart } = (await import(
/* webpackIgnore: true */ /* turbopackIgnore: true */ dartEntry
)) as typeof import("codama-renderers-dart");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Check the uncompressed size of the force-included dependency namespaces to evaluate serverless bundle bloat risk.
du -sh node_modules/@codama node_modules/@solana node_modules/@noble node_modules/codama-renderers-dart 2>/dev/null || echo "Run this in the environment where dependencies are installed to see the total size."

Repository: dev-jodee/castaway

Length of output: 272


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the relevant files with line numbers.
sed -n '1,180p' lib/codama-generate.ts | cat -n
printf '\n--- next.config.ts ---\n'
sed -n '1,140p' next.config.ts | cat -n

printf '\n--- package manifest references ---\n'
rg -n 'codama-renderers-dart|`@codama/`|`@solana/`|`@noble/`' package.json pnpm-lock.yaml yarn.lock package-lock.json 2>/dev/null || true

printf '\n--- package size snapshots ---\n'
du -sh node_modules/@codama node_modules/@solana node_modules/@noble node_modules/codama-renderers-dart 2>/dev/null || true

Repository: dev-jodee/castaway

Length of output: 50374


🏁 Script executed:

#!/bin/bash
set -euo pipefail

pkg=node_modules/codama-renderers-dart

printf '--- package.json exports/imports ---\n'
python3 - <<'PY'
import json, pathlib
p = pathlib.Path("node_modules/codama-renderers-dart/package.json")
data = json.loads(p.read_text())
for k in ("name", "version", "type", "main", "module", "exports", "files"):
    if k in data:
        print(f"{k}: {data[k]}")
PY

printf '\n--- dist files ---\n'
find "$pkg/dist" -maxdepth 2 -type f | sed 's#^`#-` #' | sort | head -n 80

printf '\n--- package root files ---\n'
find "$pkg" -maxdepth 1 -type f | sed 's#^`#-` #' | sort

Repository: dev-jodee/castaway

Length of output: 247


🏁 Script executed:

#!/bin/bash
set -euo pipefail

pkg=node_modules/codama-renderers-dart

echo '--- package.json exports/imports ---'
python3 - <<'PY'
import json, pathlib
p = pathlib.Path("node_modules/codama-renderers-dart/package.json")
data = json.loads(p.read_text())
for k in ("name", "version", "type", "main", "module", "exports", "files"):
    if k in data:
        print(f"{k}: {data[k]}")
PY

echo
echo '--- dist files ---'
find "$pkg/dist" -maxdepth 2 -type f | sort | sed 's#^`#-` #'

echo
echo '--- package root files ---'
find "$pkg" -maxdepth 1 -type f | sort | sed 's#^`#-` #'

Repository: dev-jodee/castaway

Length of output: 1520


Patch codama-renderers-dart to remove the runtime import workaround.
codama-renderers-dart@0.4.1 still points node.import at a missing dist/index.node.mjs, so the path-based import is understandable; the follow-on outputFileTracingIncludes globs are the risky part, since they pull in large @codama/@solana/@noble trees. Fixing the package exports would let Next trace only the needed files and drop both the hardcoded path and the broad includes.

📍 Affects 2 files
  • lib/codama-generate.ts#L94-L107 (this comment)
  • next.config.ts#L27-L36
🤖 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 `@lib/codama-generate.ts` around lines 94 - 107, Patch codama-renderers-dart’s
exports so node.import resolves to the existing ESM entry, then simplify
lib/codama-generate.ts by replacing the hardcoded dartEntry path-based import
with the normal package import while preserving lazy loading. Remove the broad
outputFileTracingIncludes workaround in next.config.ts; both sites require
changes, with Next tracing the package’s correctly exported dependencies
directly.

dev-jodee added a commit that referenced this pull request Jul 23, 2026
Refresh dependencies to latest and add a Dart client renderer, loaded
lazily via its ESM build and bundled for Vercel. Squashes #6-#9.
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