From 1c34419be47ba4e3eaf9837f1ec84d1af091001f Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 22 Jun 2026 14:15:48 +0000 Subject: [PATCH 1/2] fix(nodejs plugin): warn when Corepack is enabled but unavailable When DEVBOX_COREPACK_ENABLED is set, the nodejs plugin's init_hook runs `corepack enable`. Some Node packages no longer bundle Corepack (nodejs-slim, and Node.js 25+), so this silently failed and users later hit a cryptic `corepack: command not found` / `yarn: command not found` without any indication of the cause. Detect the missing `corepack` binary (ENOENT) and print an actionable warning pointing users to add the `corepack` package, instead of failing silently. Other failures (e.g. being offline) are still ignored so they don't block shell initialization. Also clarify the plugin readme to call out nodejs-slim and add a testscript case covering the nodejs-slim path. Fixes #2791 --- plugins/nodejs.json | 4 +- plugins/nodejs/setup-corepack.mjs | 39 +++++++++++++++++-- .../nodejs_corepack_autodetect.test.txt | 10 +++++ 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/plugins/nodejs.json b/plugins/nodejs.json index bc398057744..9153dd4f186 100644 --- a/plugins/nodejs.json +++ b/plugins/nodejs.json @@ -1,8 +1,8 @@ { "$schema": "https://raw.githubusercontent.com/jetify-com/devbox/main/.schema/devbox-plugin.schema.json", - "version": "0.0.4", + "version": "0.0.5", "name": "nodejs", - "readme": "Devbox automatically configures Corepack for Nodejs when DEVBOX_COREPACK_ENABLED=1. You can install Yarn or Pnpm by adding them to your `package.json` file using `packageManager`\nCorepack binaries will be installed in your local `.devbox` directory\n\nWhen Corepack is enabled, Devbox also activates the package manager pinned in your `package.json` `packageManager` field automatically. Set DEVBOX_DISABLE_NODEJS_PACKAGE_MANAGER_AUTODETECT=1 to disable this behavior.\n\nNote: newer versions of Nodejs (25+) no longer bundle Corepack, so you must add the `corepack` package to your devbox.json separately for Corepack to be available.", + "readme": "Devbox automatically configures Corepack for Nodejs when DEVBOX_COREPACK_ENABLED=1. You can install Yarn or Pnpm by adding them to your `package.json` file using `packageManager`\nCorepack binaries will be installed in your local `.devbox` directory\n\nWhen Corepack is enabled, Devbox also activates the package manager pinned in your `package.json` `packageManager` field automatically. Set DEVBOX_DISABLE_NODEJS_PACKAGE_MANAGER_AUTODETECT=1 to disable this behavior.\n\nNote: some Nodejs packages do not bundle Corepack, including `nodejs-slim` and newer Nodejs versions (25+). With those packages you must add the `corepack` package to your devbox.json separately (for example, run `devbox add corepack`) for Corepack to be available.", "env": { "DEVBOX_COREPACK_BIN_DIR": "{{ .Virtenv }}/corepack-bin", "PATH": "{{ .Virtenv }}/corepack-bin:$PATH" diff --git a/plugins/nodejs/setup-corepack.mjs b/plugins/nodejs/setup-corepack.mjs index 1ca1dd175cc..8eeba684975 100644 --- a/plugins/nodejs/setup-corepack.mjs +++ b/plugins/nodejs/setup-corepack.mjs @@ -27,11 +27,42 @@ if (!corepackBinDir) { process.exit(0); } -// Enable Corepack, installing the pnpm/yarn/npm shims into corepackBinDir. -run("corepack", ["enable", "--install-directory", corepackBinDir]); +// Enable Corepack, installing the pnpm/yarn/npm shims into corepackBinDir. If +// Corepack isn't available there's nothing more to do, so skip activation. +if (enableCorepack()) { + // Activate the package manager pinned in package.json's "packageManager" + // field. + activatePinnedPackageManager(); +} + +// enableCorepack runs `corepack enable`. It returns true on success. If the +// `corepack` binary itself is missing it prints an actionable warning and +// returns false, because some Node packages (such as nodejs-slim, and Node.js +// 25+) no longer bundle Corepack (see issue #2791). Other failures (e.g. being +// offline) are ignored so they don't block shell initialization. +function enableCorepack() { + try { + execFileSync("corepack", ["enable", "--install-directory", corepackBinDir], { + stdio: "inherit", + }); + return true; + } catch (err) { + if (err && err.code === "ENOENT") { + warnCorepackUnavailable(); + } + return false; + } +} -// Activate the package manager pinned in package.json's "packageManager" field. -activatePinnedPackageManager(); +function warnCorepackUnavailable() { + process.stderr.write( + "[devbox] Warning: DEVBOX_COREPACK_ENABLED is set but the `corepack` " + + "command was not found. Some Node packages (such as nodejs-slim, and " + + "Node.js 25+) no longer bundle Corepack. Add the `corepack` package to " + + "your devbox.json (for example, run `devbox add corepack`) to use " + + "Yarn or pnpm.\n", + ); +} function activatePinnedPackageManager() { if (process.env.DEVBOX_DISABLE_NODEJS_PACKAGE_MANAGER_AUTODETECT) { diff --git a/testscripts/plugin/nodejs_corepack_autodetect.test.txt b/testscripts/plugin/nodejs_corepack_autodetect.test.txt index 6b75c9b7f5f..7cad0cd774e 100644 --- a/testscripts/plugin/nodejs_corepack_autodetect.test.txt +++ b/testscripts/plugin/nodejs_corepack_autodetect.test.txt @@ -30,6 +30,16 @@ cp package-esm.json package.json exec devbox run -- node -e 'console.log("case3-ok")' stdout 'case3-ok' +# Case 4: a Node package that does not bundle Corepack, e.g. nodejs-slim +# (issue #2791). Shell init must still succeed, and the plugin must print an +# actionable warning instead of failing later with a cryptic +# "corepack: command not found". +exec devbox rm nodejs +exec devbox add nodejs-slim +exec devbox run -- node -e 'console.log("case4-ok")' +stdout 'case4-ok' +stderr 'command was not found' + -- package-no-pkgmgr.json -- { "name": "nodejs-corepack-autodetect", From bb78a868861d99613219efd90912660aab86889d Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 22 Jun 2026 14:19:31 +0000 Subject: [PATCH 2/2] nodejs plugin: address review feedback - Reword the activation gate comment: activation is skipped on any enableCorepack() failure, not only when Corepack is missing. - Tighten the testscript stderr assertion to match the specific Corepack warning text instead of a generic "command was not found". --- plugins/nodejs/setup-corepack.mjs | 5 +++-- testscripts/plugin/nodejs_corepack_autodetect.test.txt | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/nodejs/setup-corepack.mjs b/plugins/nodejs/setup-corepack.mjs index 8eeba684975..4e4d2796c12 100644 --- a/plugins/nodejs/setup-corepack.mjs +++ b/plugins/nodejs/setup-corepack.mjs @@ -27,8 +27,9 @@ if (!corepackBinDir) { process.exit(0); } -// Enable Corepack, installing the pnpm/yarn/npm shims into corepackBinDir. If -// Corepack isn't available there's nothing more to do, so skip activation. +// Enable Corepack, installing the pnpm/yarn/npm shims into corepackBinDir. +// Only attempt package-manager activation if enabling succeeded; if it failed +// for any reason (Corepack missing, offline, etc.) there's nothing to activate. if (enableCorepack()) { // Activate the package manager pinned in package.json's "packageManager" // field. diff --git a/testscripts/plugin/nodejs_corepack_autodetect.test.txt b/testscripts/plugin/nodejs_corepack_autodetect.test.txt index 7cad0cd774e..67ba216ad66 100644 --- a/testscripts/plugin/nodejs_corepack_autodetect.test.txt +++ b/testscripts/plugin/nodejs_corepack_autodetect.test.txt @@ -38,7 +38,7 @@ exec devbox rm nodejs exec devbox add nodejs-slim exec devbox run -- node -e 'console.log("case4-ok")' stdout 'case4-ok' -stderr 'command was not found' +stderr 'Warning: DEVBOX_COREPACK_ENABLED is set but the .corepack. command was not found' -- package-no-pkgmgr.json -- {