fix(generate): load dart renderer via its ESM build (fixes remaining dart 500) - #9
Conversation
#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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThe Dart renderer now loads its ESM entry through a dynamically generated file URL. Next.js tracing for ChangesDart renderer runtime
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
lib/codama-generate.tsnext.config.ts
| // 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"); |
There was a problem hiding this comment.
🚀 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 || trueRepository: 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#^`#-` #' | sortRepository: 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.
Follow-up to #8
#8 stopped the total outage (typescript/umi/rust/go work again), but dart itself still 500'd on production:
Why: dart's CJS build (loaded via
createRequire) requires the.cjsvariants of a large@codama/@solana/codecs/@noble/hashestree. Next only bundles those packages as.mjs(the js/rust/go renderers import them via ESM), so the.cjsfiles aren't in the lambda.Fix
/* webpackIgnore */ /* turbopackIgnore */so Turbopack leaves it as a runtime import (a plain dynamicimport()of a computed path throws Turbopack's "expression is too dynamic"). The ESM build reuses the already-bundled.mjsdeps.outputFileTracingIncludesto guarantee dart's ESM closure (@codama,@solana,@noble) is in the generate lambda.Verification (local)
.dartfiles.*.node.cjsfiles (simulating the.mjs-only lambda) → all 5 languages, incl. dart, return 200. This is the exact failure mode from production.Summary by CodeRabbit