Skip to content

fix(nodejs plugin): warn when Corepack is unavailable instead of failing silently#2892

Open
mikeland73 wants to merge 2 commits into
mainfrom
claude/focused-goldberg-iz50ex
Open

fix(nodejs plugin): warn when Corepack is unavailable instead of failing silently#2892
mikeland73 wants to merge 2 commits into
mainfrom
claude/focused-goldberg-iz50ex

Conversation

@mikeland73

Copy link
Copy Markdown
Collaborator

Summary

Fixes #2791.

The nodejs plugin's setup-corepack.mjs init_hook runs corepack enable and silently swallows any failure. On nodejs-slim and Node.js 25+ — which no longer bundle Corepack — this leaves users with a cryptic, unexplained failure at shell startup:

bash: corepack: command not found
bash: yarn: command not found

…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:

[devbox] nodejs plugin: `corepack` was not found, so Corepack-managed package managers (such as yarn and pnpm) will be unavailable.
[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.

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 enable and corepack prepare --activate <packageManager> run exactly as before.

The plugin version is bumped 0.0.40.0.5 so cached copies in users' virtenv are refreshed.

How was it tested?

  • node --check plugins/nodejs/setup-corepack.mjs passes.
  • Ran the script against a PATH with node but no corepack: it prints the guidance above and exits 0 (non-fatal).
  • Ran it with a stub corepack on PATH and a pinned packageManager in package.json: it still calls corepack enable --install-directory … followed by corepack 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

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
Copilot AI review requested due to automatic review settings June 24, 2026 15:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ENOENT handling in setup-corepack.mjs to warn when corepack is not available and skip activation.
  • Refactor run() to return a boolean and gate activation based on corepack enable success.
  • 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 thread plugins/nodejs/setup-corepack.mjs Outdated
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 thread plugins/nodejs/setup-corepack.mjs Outdated
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
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.

Node.js plugin fails to run corepack when using nodejs-slim

3 participants