fix(nodejs plugin): warn when Corepack is unavailable instead of failing silently#2892
Open
mikeland73 wants to merge 2 commits into
Open
fix(nodejs plugin): warn when Corepack is unavailable instead of failing silently#2892mikeland73 wants to merge 2 commits into
mikeland73 wants to merge 2 commits into
Conversation
The nodejs plugin's setup-corepack init_hook ran `corepack enable` and swallowed any failure silently. On nodejs-slim and Node.js 25+, which no longer bundle Corepack, this left users with a cryptic "corepack: command not found" / "yarn: command not found" at shell startup and no indication of the cause. Detect the missing-binary (ENOENT) case and print actionable guidance pointing users to `devbox add corepack`, then cleanly skip package manager activation. The happy path (Corepack present) is unchanged. Fixes #2791 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MEAWvyABicqkLncj6irnQq
Contributor
There was a problem hiding this comment.
Pull request overview
Improves the Node.js plugin’s Corepack initialization hook so users get actionable guidance when corepack is missing (e.g., nodejs-slim / Node.js 25+), instead of failing silently and leaving downstream “command not found” errors.
Changes:
- Add
ENOENThandling insetup-corepack.mjsto warn whencorepackis not available and skip activation. - Refactor
run()to return a boolean and gate activation based oncorepack enablesuccess. - Bump the nodejs plugin version to refresh cached copies in existing virtenvs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| plugins/nodejs/setup-corepack.mjs | Detect missing Corepack and print actionable guidance; adjust execution flow around Corepack enable/activation. |
| plugins/nodejs.json | Bump plugin version from 0.0.4 to 0.0.5 to ensure updated plugin content is picked up. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
79
to
97
| // ENOENT means the command itself is missing. For Corepack this happens | ||
| // with nodejs-slim and Node.js 25+, which no longer bundle it (see issue | ||
| // #2791). Without a message, the user is left with a cryptic | ||
| // "command not found" for yarn/pnpm and no idea why, so point them at the | ||
| // fix instead of failing silently. | ||
| if (err && err.code === "ENOENT") { | ||
| console.error( | ||
| `[devbox] nodejs plugin: \`${command}\` was not found, so Corepack-managed ` + | ||
| `package managers (such as yarn and pnpm) will be unavailable.`, | ||
| ); | ||
| console.error( | ||
| `[devbox] Your Node.js package does not bundle Corepack (e.g. nodejs-slim, ` + | ||
| `or Node.js 25+). Add it explicitly with \`devbox add corepack\` to enable it.`, | ||
| ); | ||
| return false; | ||
| } | ||
| // Other failures (e.g. offline during activation) are non-fatal. | ||
| return false; | ||
| } |
Comment on lines
+71
to
+73
| // Run a command, inheriting stdio so Corepack's output is visible. Returns | ||
| // true on success and false on failure. Failures must not block shell | ||
| // initialization, so errors are reported but never rethrown. |
Address review feedback: the previous revision skipped package-manager activation whenever `corepack enable` failed for any reason. Restrict the early-exit to the missing-binary (ENOENT) case so transient, non-ENOENT failures remain non-fatal and still attempt activation, matching the plugin's prior behavior. Move the missing-Corepack guidance into a dedicated warnCorepackMissing() helper and restore run() to its simple swallow-all contract. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MEAWvyABicqkLncj6irnQq
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2791.
The nodejs plugin's
setup-corepack.mjsinit_hook runscorepack enableand silently swallows any failure. Onnodejs-slimand Node.js 25+ — which no longer bundle Corepack — this leaves users with a cryptic, unexplained failure at shell startup:…and no indication of why Corepack/yarn are missing or how to fix it.
Fix
run()now detects the missing-binary case (ENOENT) and prints actionable guidance pointing the user at the documented fix, then cleanly skips package-manager activation:This matches the guidance already present in the plugin's
readme. Shell initialization still succeeds (the warning is non-fatal) and the happy path is unchanged: when Corepack is present,corepack enableandcorepack prepare --activate <packageManager>run exactly as before.The plugin
versionis bumped0.0.4→0.0.5so cached copies in users'virtenvare refreshed.How was it tested?
node --check plugins/nodejs/setup-corepack.mjspasses.PATHwithnodebut nocorepack: it prints the guidance above and exits 0 (non-fatal).corepackonPATHand a pinnedpackageManagerinpackage.json: it still callscorepack enable --install-directory …followed bycorepack prepare --activate yarn@4.0.0, confirming the happy path is unaffected.cc @apgrucza (issue reporter)
🤖 Generated with Claude Code
https://claude.ai/code/session_01MEAWvyABicqkLncj6irnQq
Generated by Claude Code