Skip to content

fix(nodejs plugin): create corepack-bin before enabling Corepack - #3042

Merged
mikeland73 merged 1 commit into
mainfrom
claude/corepack-enoent-error-34fa75
Nov 5, 2026
Merged

mikeland73 merged 1 commit into
mainfrom
claude/corepack-enoent-error-34fa75

Conversation

@mikeland73

Copy link
Copy Markdown
Collaborator

Summary

With DEVBOX_COREPACK_ENABLED set, every devbox run / devbox shell can fail in the nodejs plugin's init hook with:

Internal Error: ENOENT: no such file or directory, lstat '<project>/.devbox/virtenv/nodejs/corepack-bin'
    at Object.realpathSync (node:fs:...)
    at EnableCommand.execute (.../corepack.cjs:...)

corepack-bin is an empty directory the plugin creates through create_files. Devbox only runs create_files during a full recompute. If the directory goes missing while .devbox/state.json is still up to date, devbox doesn't recreate it, and corepack enable --install-directory fails because the directory doesn't exist. One way this happens is a .devbox copied into a new git worktree: the copy keeps setup-corepack.mjs but drops empty directories.

Changes

  • plugins/nodejs/setup-corepack.mjs: create the install directory (mkdirSync(..., { recursive: true })) before running corepack enable.
  • plugins/nodejs.json: bump the plugin version to 0.0.6.
  • testscripts/plugin/nodejs_corepack_autodetect.test.txt: new case that deletes corepack-bin while state is up to date, then checks that devbox run succeeds, prints no ENOENT, and installs the pnpm shim.

Testing

  • go test ./testscripts -run 'TestScripts/nodejs_corepack_autodetect' passes. With the script change reverted, the new case fails.
  • Tested by hand with a local build and nodejs@24: after deleting corepack-bin, devbox run reproduced the error before the fix. After the fix, it recreates the directory, and which pnpm resolves into corepack-bin.

🤖 Generated with Claude Code

`corepack enable --install-directory` fails with ENOENT when the install
directory doesn't exist. The plugin's create_files makes that directory,
but devbox only runs create_files during a full recompute, so if the
directory goes missing while .devbox/state.json is still up to date
(for example a .devbox copied into a new git worktree without its empty
directories), every devbox run and shell fails in the init hook.

setup-corepack.mjs now creates the directory itself before running
`corepack enable`. Bump the plugin version to 0.0.6.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@claude

claude Bot commented Nov 5, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@mikeland73

Copy link
Copy Markdown
Collaborator Author

@claude ptal

@claude

claude Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Claude finished @mikeland73's task in 14s —— View job


Review of PR #3042

I read the diff and found nothing that should block merging.

  • Fix (plugins/nodejs/setup-corepack.mjs): mkdirSync(corepackBinDir, { recursive: true }) runs right before corepack enable, which matches the root cause. It does nothing when the directory already exists. It also sits inside the existing try, so if mkdirSync throws (for example on permissions), the error is handled like any other corepack enable failure and doesn't block shell init.
  • Version bump (plugins/nodejs.json): 0.0.5 to 0.0.6 is needed so existing projects pick up the changed script.
  • Test (nodejs_corepack_autodetect.test.txt): Case 3b covers the regression. It deletes corepack-bin while state is current, then checks that devbox run succeeds, stderr has no ENOENT, and the pnpm shim exists. You report that it fails with the fix reverted, which is the check that matters.

Optional nits:

  • The ! stderr 'ENOENT' check only works if the test doesn't redirect or swallow stderr elsewhere. That looks fine here.
  • The code comment is a bit long. It's still useful context.

I did not run the tests myself. I relied on the results in the PR description.
· branch claude/corepack-enoent-error-34fa75

@mikeland73
mikeland73 merged commit 8754743 into main Nov 5, 2026
28 checks passed
@mikeland73
mikeland73 deleted the claude/corepack-enoent-error-34fa75 branch November 5, 2026 06:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant