Skip to content

fix: resolve MODULE_NOT_FOUND for claude-agent-sdk cli.js in RDE config updates - #1639

Merged
N2D4 merged 3 commits into
devfrom
devin/1782154187-fix-rde-config-agent-cli-js
Jun 23, 2026
Merged

N2D4 merged 3 commits into
devfrom
devin/1782154187-fix-rde-config-agent-cli-js

Conversation

@mantrakp04

@mantrakp04 mantrakp04 commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes MODULE_NOT_FOUND for @anthropic-ai/claude-agent-sdk/cli.js when the RDE config updater runs.

The SDK was bundled by Turbopack, which baked the .pnpm/ store path into import.meta.url. copy-runtime-assets then removed .pnpm/, so cli.js vanished at runtime.

# next.config.mjs
+ serverExternalPackages: ["@anthropic-ai/claude-agent-sdk"]
- outputFileTracingIncludes: { ... cli.js, vendor/**, ... }
# copy-runtime-assets.mjs — removePnpmStore()
  hoistPnpmNodeModules(pnpmDir);
+ hoistPnpmStorePackages(pnpmDir);  // hoist .pnpm/<spec>/node_modules/<pkg>/ → node_modules/<pkg>/
  rmSync(pnpmDir, ...);

serverExternalPackages keeps the SDK external so (a) import.meta.url resolves to the actual runtime path, and (b) Next.js traces the entire package directory into standalone output. hoistPnpmStorePackages ensures those files survive .pnpm removal. The old outputFileTracingIncludes was 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.js during 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

    • Set serverExternalPackages: ["@anthropic-ai/claude-agent-sdk"] in apps/dashboard/next.config.mjs so import.meta.url resolves at runtime and the full package is traced.
    • Added hoistPnpmStorePackages() in packages/cli/scripts/copy-runtime-assets.mjs to copy .pnpm/<spec>/node_modules/<pkg>/ into top-level node_modules/ before removing .pnpm.
    • Create @scope/ directories with mkdirSync before copying hoisted packages to prevent ENOENT.
  • Refactors

    • Removed manual outputFileTracingIncludes for the SDK since externalizing the package includes its entire directory automatically.

Written for commit 67b9013. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Chores
    • Improved dashboard build/packaging behavior to better preserve required runtime files in standalone outputs.
    • Refined runtime asset handling to hoist additional packages from pnpm store locations into top-level node_modules, reducing missing-module risks after .pnpm removal.
    • Updated build configuration logic to use ESM-compatible path resolution for more consistent packaging.

devin-ai-integration Bot and others added 2 commits June 22, 2026 18:49
…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]>
@mantrakp04 mantrakp04 self-assigned this Jun 22, 2026
@devin-ai-integration

Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@vercel

vercel Bot commented Jun 22, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
stack-auth-hosted-components Ready Ready Preview, Comment Jun 22, 2026 7:11pm
stack-auth-internal-tool Error Error Jun 22, 2026 7:11pm
stack-auth-mcp Ready Ready Preview, Comment Jun 22, 2026 7:11pm
stack-auth-skills Ready Ready Preview, Comment Jun 22, 2026 7:11pm
stack-backend Ready Ready Preview, Comment Jun 22, 2026 7:11pm
stack-dashboard Ready Ready Preview, Comment Jun 22, 2026 7:11pm
stack-demo Ready Ready Preview, Comment Jun 22, 2026 7:11pm
stack-docs Error Error Jun 22, 2026 7:11pm
stack-preview-backend Ready Ready Preview, Comment Jun 22, 2026 7:11pm
stack-preview-dashboard Ready Ready Preview, Comment Jun 22, 2026 7:11pm

@coderabbitai

coderabbitai Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 151aab7c-a1ac-406d-8175-408f864598a8

📥 Commits

Reviewing files that changed from the base of the PR and between 4adfe36 and 67b9013.

📒 Files selected for processing (1)
  • packages/cli/scripts/copy-runtime-assets.mjs
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/cli/scripts/copy-runtime-assets.mjs

📝 Walkthrough

Walkthrough

The Next.js dashboard config switches from createRequire-based path resolution to ESM imports and replaces outputFileTracingIncludes for @anthropic-ai/claude-agent-sdk with serverExternalPackages. The CLI copy-runtime-assets script adds getPackageNameFromPnpmSpecifier() and hoistPnpmStorePackages() to copy pnpm store package directories into top-level node_modules before .pnpm is deleted.

Changes

Standalone Packaging for @anthropic-ai/claude-agent-sdk

Layer / File(s) Summary
Next.js ESM cleanup and serverExternalPackages
apps/dashboard/next.config.mjs
Removes createRequire and claude-agent-sdk path constants; computes __dirname from import.meta.url; replaces outputFileTracingIncludes with serverExternalPackages: ["@anthropic-ai/claude-agent-sdk"].
CLI pnpm store hoisting helpers and integration
packages/cli/scripts/copy-runtime-assets.mjs
Adds mkdirSync to imports; adds getPackageNameFromPnpmSpecifier() to parse specifier strings (scoped packages, +-to-/ translation); adds hoistPnpmStorePackages() to iterate .pnpm entries and copy validated packages into top-level node_modules; calls both in removePnpmStore() before deleting .pnpm.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • hexclave/hexclave#1537: Introduced @anthropic-ai/claude-agent-sdk usage in the dashboard, directly motivating the packaging changes in this PR.
  • hexclave/hexclave#1544: Contains prior pnpm hoisting and store cleanup logic in copy-runtime-assets.mjs that this PR extends.

Poem

🐰 Hop through the .pnpm store with glee,
Hoist each package where it needs to be!
No more createRequire in the night,
ESM paths now shine so bright.
External packages, standalone and free — ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: resolving MODULE_NOT_FOUND for claude-agent-sdk cli.js through RDE config updates.
Description check ✅ Passed The description is comprehensive, including problem statement, root cause, solution details with code diffs, and context links.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch devin/1782154187-fix-rde-config-agent-cli-js

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.

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 2 files

Re-trigger cubic

@greptile-apps

greptile-apps Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a MODULE_NOT_FOUND error for @anthropic-ai/claude-agent-sdk/cli.js in RDE standalone builds by replacing a fragile manual outputFileTracingIncludes workaround with serverExternalPackages, and adding a hoistPnpmStorePackages step to ensure pnpm store packages survive .pnpm directory removal.

  • next.config.mjs: Removes the hand-curated outputFileTracingIncludes file list and adds serverExternalPackages: ["@anthropic-ai/claude-agent-sdk"], causing Next.js to trace the entire package directory (including cli.js, vendor/, etc.) into the standalone output and keeping import.meta.url resolvable at runtime.
  • copy-runtime-assets.mjs: Adds getPackageNameFromPnpmSpecifier (decodes pnpm's +-encoded specifier names) and hoistPnpmStorePackages (copies .pnpm/<specifier>/node_modules/<pkg> to top-level node_modules/ before .pnpm is removed), acting as a safety net for packages not already hoisted via top-level symlinks.

Confidence Score: 4/5

The 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

Filename Overview
apps/dashboard/next.config.mjs Replaces brittle outputFileTracingIncludes manual file list with serverExternalPackages, correctly directing Next.js to trace the full claude-agent-sdk package directory into the standalone output.
packages/cli/scripts/copy-runtime-assets.mjs Adds hoistPnpmStorePackages to copy .pnpm//node_modules/ to top-level node_modules before .pnpm removal; missing mkdirSync for intermediate @scope/ directories of scoped packages not yet present at destination could cause ENOENT in edge cases.

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
Loading
%%{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
Loading

Fix All in Claude Code Fix All in Cursor Fix All in Codex

Prompt To Fix All With AI
Fix 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]>
@N2D4
N2D4 merged commit 28b559b into dev Jun 23, 2026
22 of 27 checks passed
@N2D4
N2D4 deleted the devin/1782154187-fix-rde-config-agent-cli-js branch June 23, 2026 17:53

This branch had an error being deployed

1 failed and 4 active deployments
Preview – stack-preview-backend — 67b9013e Deployed Jun 22, 2026 by vercel[bot]
Preview – stack-preview-dashboard — 67b9013e Deployed Jun 22, 2026 by vercel[bot]
Preview – stack-auth-internal-tool — 67b9013e Deployed Jun 22, 2026 by vercel[bot]
Preview – stack-auth-mcp — 67b9013e Deployed Jun 22, 2026 by vercel[bot]
Preview – stack-auth-skills — 67b9013e Deployed Jun 22, 2026 by vercel[bot]
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.

2 participants