Skip to content

Commit 0fdf1e6

Browse files
authored
Fix hydrogen upgrade failing with yarn (#3462)
* Fix hydrogen upgrade failing with yarn The upgrade command was using `installNodeModules` which always runs `<pm> install <packages>`. This works for npm, pnpm, and bun but fails for yarn which requires `add` instead of `install` when adding/upgrading specific packages. Mirror the pattern already used by `uninstallNodeModules` which correctly maps the subcommand per package manager. * Fix pnpm command mapping to use 'add' instead of 'install' Use exhaustive per-PM branch pattern matching uninstallNodeModules() to correctly map each package manager to its install subcommand. pnpm requires 'add' for specific packages, not 'install'. * Extract resolvePackageManagerName helper Deduplicate the 'unknown' → 'npm' normalization logic shared between upgradeNodeModules and uninstallNodeModules. * docs: update changeset to mention both yarn and pnpm fix * docs: add comment explaining why installNodeModules was replaced
1 parent 5c41859 commit 0fdf1e6

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/cli-hydrogen': patch
3+
---
4+
5+
Fix `hydrogen upgrade` failing with yarn and pnpm by using the correct package-specific install subcommand (`add` for yarn/pnpm, `install` for npm/bun) when upgrading dependencies

packages/cli/src/commands/hydrogen/upgrade.ts

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
} from '@shopify/cli-kit/node/fs';
2424
import {
2525
getDependencies,
26-
installNodeModules,
2726
getPackageManager,
2827
type PackageJson,
2928
} from '@shopify/cli-kit/node/node-package-manager';
@@ -979,7 +978,9 @@ export async function upgradeNodeModules({
979978
});
980979
}
981980

982-
// Then install/upgrade dependencies
981+
// Install/upgrade dependencies using exec() directly instead of cli-kit's
982+
// installNodeModules(), which runs `<pm> install` and doesn't support adding
983+
// specific packages with version specifiers (yarn/pnpm require `add`).
983984
const upgradeArgs = buildUpgradeCommandArgs({
984985
selectedRelease,
985986
currentDependencies,
@@ -990,11 +991,24 @@ export async function upgradeNodeModules({
990991
tasks.push({
991992
title: `Upgrading dependencies`,
992993
task: async () => {
993-
await installNodeModules({
994-
directory: appPath,
995-
packageManager: await getPackageManager(appPath),
996-
args: upgradeArgs,
997-
});
994+
const packageManager = await getPackageManager(appPath);
995+
const command =
996+
packageManager === 'npm'
997+
? 'install'
998+
: packageManager === 'yarn'
999+
? 'add'
1000+
: packageManager === 'pnpm'
1001+
? 'add'
1002+
: packageManager === 'bun'
1003+
? 'install'
1004+
: 'install'; // fallback to npm for 'unknown'
1005+
await exec(
1006+
resolvePackageManagerName(packageManager),
1007+
[command, ...upgradeArgs],
1008+
{
1009+
cwd: appPath,
1010+
},
1011+
);
9981012
},
9991013
});
10001014
}
@@ -1004,6 +1018,15 @@ export async function upgradeNodeModules({
10041018
}
10051019
}
10061020

1021+
/**
1022+
* Normalizes the package manager name, falling back to npm for 'unknown'.
1023+
*/
1024+
function resolvePackageManagerName(
1025+
packageManager: 'npm' | 'yarn' | 'pnpm' | 'unknown' | 'bun',
1026+
): 'npm' | 'yarn' | 'pnpm' | 'bun' {
1027+
return packageManager === 'unknown' ? 'npm' : packageManager;
1028+
}
1029+
10071030
/**
10081031
* Uninstalls the specified dependencies
10091032
*/
@@ -1029,10 +1052,9 @@ async function uninstallNodeModules({
10291052
? 'remove'
10301053
: 'uninstall'; // fallback to npm for 'unknown'
10311054

1032-
const actualPackageManager =
1033-
packageManager === 'unknown' ? 'npm' : packageManager;
1034-
1035-
await exec(actualPackageManager, [command, ...args], {cwd: directory});
1055+
await exec(resolvePackageManagerName(packageManager), [command, ...args], {
1056+
cwd: directory,
1057+
});
10361058
}
10371059

10381060
/**

0 commit comments

Comments
 (0)