Repository navigation
fix: resolve MODULE_NOT_FOUND for claude-agent-sdk cli.js in RDE config updates - #1639
Conversation
…ig updates The RDE config updater failed with MODULE_NOT_FOUND for cli.js because: 1. Turbopack bakes import.meta.url with the .pnpm store path at build time 2. copy-runtime-assets removes .pnpm after hoisting, but only hoisted symlinks and .pnpm/node_modules/ shared deps — not the primary package directories under .pnpm/<specifier>/node_modules/<name>/ Fix: - Add @anthropic-ai/claude-agent-sdk to serverExternalPackages so it loads from node_modules/ at runtime (correct import.meta.url resolution) - Add hoistPnpmStorePackages() to copy-runtime-assets.mjs to hoist primary packages from .pnpm/<specifier>/node_modules/ to the top-level node_modules/ before removing .pnpm Co-Authored-By: mantra <[email protected]>
serverExternalPackages causes Next.js to include the entire package directory in the standalone trace automatically, making the manual outputFileTracingIncludes entries unnecessary. Co-Authored-By: mantra <[email protected]>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe Next.js dashboard config switches from ChangesStandalone Packaging for
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
Greptile SummaryThis PR fixes a
Confidence Score: 4/5The core fix is sound — serverExternalPackages correctly solves the import.meta.url / cli.js tracing problem. The new hoistPnpmStorePackages function has a missing mkdirSync guard for scoped packages whose scope directory doesn't yet exist at the destination, which could throw ENOENT for scoped sub-dependencies of external packages in certain pnpm layouts. The next.config.mjs change is clean and correct. The hoistPnpmStorePackages function works for the primary use case (claude-agent-sdk's @anthropic-ai/ scope already exists at the destination), but the missing mkdirSync for intermediate scope directories means a scoped sub-dependency under a novel scope could cause the copy-runtime-assets script to throw and abort the build. packages/cli/scripts/copy-runtime-assets.mjs — specifically the cpSync call inside hoistPnpmStorePackages for scoped packages. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["Next.js build\n(serverExternalPackages:\nclaude-agent-sdk)"] --> B["Standalone output\nnext/standalone/node_modules/\n@anthropic-ai/claude-agent-sdk → symlink\n.pnpm/@anthropic-ai+claude-agent-sdk@X/\nnode_modules/@anthropic-ai/claude-agent-sdk"]
B --> C["cpSync with dereference:true\n→ dashboardDist"]
C --> D["dashboardDist/node_modules/\n@anthropic-ai/claude-agent-sdk/ ✔ (real dir)\n.pnpm/.../claude-agent-sdk/ ✔ (duplicate)"]
D --> E["hoistPnpmNodeModules\n(.pnpm/node_modules/ → top-level)"]
E --> F["hoistPnpmStorePackages\n(.pnpm/<specifier>/node_modules/<pkg>\n→ top-level if not already there)"]
F --> G["rmSync .pnpm/ dir"]
G --> H["dashboardDist/node_modules/\n@anthropic-ai/claude-agent-sdk/ ✔\ncli.js, vendor/, etc. intact"]
style A fill:#d4edda
style H fill:#d4edda
style G fill:#f8d7da
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A["Next.js build\n(serverExternalPackages:\nclaude-agent-sdk)"] --> B["Standalone output\nnext/standalone/node_modules/\n@anthropic-ai/claude-agent-sdk → symlink\n.pnpm/@anthropic-ai+claude-agent-sdk@X/\nnode_modules/@anthropic-ai/claude-agent-sdk"]
B --> C["cpSync with dereference:true\n→ dashboardDist"]
C --> D["dashboardDist/node_modules/\n@anthropic-ai/claude-agent-sdk/ ✔ (real dir)\n.pnpm/.../claude-agent-sdk/ ✔ (duplicate)"]
D --> E["hoistPnpmNodeModules\n(.pnpm/node_modules/ → top-level)"]
E --> F["hoistPnpmStorePackages\n(.pnpm/<specifier>/node_modules/<pkg>\n→ top-level if not already there)"]
F --> G["rmSync .pnpm/ dir"]
G --> H["dashboardDist/node_modules/\n@anthropic-ai/claude-agent-sdk/ ✔\ncli.js, vendor/, etc. intact"]
style A fill:#d4edda
style H fill:#d4edda
style G fill:#f8d7da
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
packages/cli/scripts/copy-runtime-assets.mjs:163-166
Missing intermediate directory creation for scoped packages. When `packageName` is scoped (e.g. `@anthropic-ai/claude-agent-sdk`), `dest` is `destNodeModules/@anthropic-ai/claude-agent-sdk`. If the `@anthropic-ai/` directory doesn't already exist at `destNodeModules`, `cpSync` will throw `ENOENT` because it doesn't create missing parent directories. This can happen for any scoped sub-dependency whose scope isn't shared with a top-level package that was already traced.
```suggestion
const dest = join(destNodeModules, packageName);
if (!existsSync(dest)) {
const scopeDir = packageName.includes("/") ? join(destNodeModules, packageName.split("/")[0]) : null;
if (scopeDir && !existsSync(scopeDir)) {
mkdirSync(scopeDir, { recursive: true });
}
cpSync(packageDir, dest, { recursive: true, dereference: true });
}
```
Reviews (1): Last reviewed commit: "refactor: remove redundant outputFileTra..." | Re-trigger Greptile |
cpSync throws ENOENT if the @scope/ parent directory doesn't exist. Create it before copying. Co-Authored-By: mantra <[email protected]>
Summary
Fixes
MODULE_NOT_FOUNDfor@anthropic-ai/claude-agent-sdk/cli.jswhen the RDE config updater runs.The SDK was bundled by Turbopack, which baked the
.pnpm/store path intoimport.meta.url.copy-runtime-assetsthen removed.pnpm/, socli.jsvanished at runtime.serverExternalPackageskeeps the SDK external so (a)import.meta.urlresolves to the actual runtime path, and (b) Next.js traces the entire package directory into standalone output.hoistPnpmStorePackagesensures those files survive.pnpmremoval. The oldoutputFileTracingIncludeswas a partial workaround that never fully solved the problem — removed.Link to Devin session: https://app.devin.ai/sessions/a6a5979df5d14204ba7da7af26389200
Requested by: @mantrakp04
Summary by cubic
Fixes MODULE_NOT_FOUND for
@anthropic-ai/claude-agent-sdk/cli.jsduring RDE config updates by keeping the SDK external and hoisting its files out of.pnpm/before cleanup. Also handles scoped packages to avoid copy errors.Bug Fixes
serverExternalPackages: ["@anthropic-ai/claude-agent-sdk"]inapps/dashboard/next.config.mjssoimport.meta.urlresolves at runtime and the full package is traced.hoistPnpmStorePackages()inpackages/cli/scripts/copy-runtime-assets.mjsto copy.pnpm/<spec>/node_modules/<pkg>/into top-levelnode_modules/before removing.pnpm.@scope/directories withmkdirSyncbefore copying hoisted packages to preventENOENT.Refactors
outputFileTracingIncludesfor the SDK since externalizing the package includes its entire directory automatically.Written for commit 67b9013. Summary will update on new commits.
Summary by CodeRabbit
node_modules, reducing missing-module risks after.pnpmremoval.