From af01ee5c3df035417ff6b773076b46aa2c0e846e Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 17 Jun 2026 14:07:29 +0000 Subject: [PATCH 1/2] Fix nodejs plugin corepack setup with "type": "module" projects The nodejs plugin's corepack init_hook script uses CommonJS `require()`, but it was named `setup-corepack.js`. When the project's root `package.json` declares `"type": "module"`, Node treats the `.js` file as an ES module and fails with "require is not defined in ES module scope", breaking `devbox shell` entirely. Rename the script to `setup-corepack.cjs` so it is always interpreted as CommonJS regardless of the project's package.json `type` field, and bump the plugin version. Adds a testscript case covering a project that declares `"type": "module"`. Fixes #2856 Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_015e5foES7T8gDQRHK3hJSdH --- plugins/nodejs.json | 6 +++--- .../{setup-corepack.js => setup-corepack.cjs} | 6 +++++- .../plugin/nodejs_corepack_autodetect.test.txt | 13 +++++++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) rename plugins/nodejs/{setup-corepack.js => setup-corepack.cjs} (87%) diff --git a/plugins/nodejs.json b/plugins/nodejs.json index 3dc93c129e4..29a23152d1c 100644 --- a/plugins/nodejs.json +++ b/plugins/nodejs.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/jetify-com/devbox/main/.schema/devbox-plugin.schema.json", - "version": "0.0.3", + "version": "0.0.4", "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.", "env": { @@ -9,11 +9,11 @@ }, "shell": { "init_hook": [ - "node \"{{ .Virtenv }}/bin/setup-corepack.js\"" + "node \"{{ .Virtenv }}/bin/setup-corepack.cjs\"" ] }, "create_files": { "{{ .Virtenv }}/corepack-bin": "", - "{{ .Virtenv }}/bin/setup-corepack.js": "nodejs/setup-corepack.js" + "{{ .Virtenv }}/bin/setup-corepack.cjs": "nodejs/setup-corepack.cjs" } } diff --git a/plugins/nodejs/setup-corepack.js b/plugins/nodejs/setup-corepack.cjs similarity index 87% rename from plugins/nodejs/setup-corepack.js rename to plugins/nodejs/setup-corepack.cjs index f2471067895..6904ffa8e21 100644 --- a/plugins/nodejs/setup-corepack.js +++ b/plugins/nodejs/setup-corepack.cjs @@ -1,5 +1,9 @@ // Configures Corepack for the Devbox shell. This is the nodejs plugin's -// init_hook, invoked as: node setup-corepack.js +// init_hook, invoked as: node setup-corepack.cjs +// +// The .cjs extension forces CommonJS regardless of the project's package.json, +// which may declare "type": "module" (otherwise the require() calls below fail +// with "require is not defined in ES module scope"). See issue #2856. // // It is a no-op unless DEVBOX_COREPACK_ENABLED is set, in which case it: // 1. Enables Corepack, installing its package-manager shims into the diff --git a/testscripts/plugin/nodejs_corepack_autodetect.test.txt b/testscripts/plugin/nodejs_corepack_autodetect.test.txt index ed10396b30b..3d132b5edb7 100644 --- a/testscripts/plugin/nodejs_corepack_autodetect.test.txt +++ b/testscripts/plugin/nodejs_corepack_autodetect.test.txt @@ -23,8 +23,21 @@ cp package-no-pkgmgr.json package.json exec devbox run -- node -e 'console.log("case2-ok")' stdout 'case2-ok' +# Case 3: package.json declares "type": "module" (issue #2856). +# The setup-corepack script must still load (it uses a .cjs extension so it is +# always treated as CommonJS) and shell init must still succeed. +cp package-esm.json package.json +exec devbox run -- node -e 'console.log("case3-ok")' +stdout 'case3-ok' + -- package-no-pkgmgr.json -- { "name": "nodejs-corepack-autodetect", "version": "1.0.0" } +-- package-esm.json -- +{ + "name": "nodejs-corepack-autodetect", + "version": "1.0.0", + "type": "module" +} From 73ec3a61ea438f37bf93626473f40045a29686de Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 17 Jun 2026 14:22:53 +0000 Subject: [PATCH 2/2] ci: re-trigger checks (clear unrelated hex.pm network flake) Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_015e5foES7T8gDQRHK3hJSdH