From af929c1ae0e50a2a5b172e1897a99bb85829039d Mon Sep 17 00:00:00 2001 From: Nathaniel Paz <54493706+Simpleboi@users.noreply.github.com> Date: Wed, 11 Feb 2026 11:38:42 -0600 Subject: [PATCH] Fixed error for create-vite with TanStack router using pnpm --- packages/create-vite/src/index.ts | 89 ++++++++++++++++--------------- 1 file changed, 47 insertions(+), 42 deletions(-) diff --git a/packages/create-vite/src/index.ts b/packages/create-vite/src/index.ts index a4e8354e92ed3f..fc915dc7627c8f 100755 --- a/packages/create-vite/src/index.ts +++ b/packages/create-vite/src/index.ts @@ -870,48 +870,53 @@ function getFullCustomCommand(customCommand: string, pkgInfo?: PkgInfo) { const pkgManager = pkgInfo ? pkgInfo.name : 'npm' const isYarn1 = pkgManager === 'yarn' && pkgInfo?.version.startsWith('1.') - return ( - customCommand - .replace(/^npm create (?:-- )?/, () => { - // `bun create` uses it's own set of templates, - // the closest alternative is using `bun x` directly on the package - if (pkgManager === 'bun') { - return 'bun x create-' - } - // Deno uses `run -A npm:create-` instead of `create` or `init` to also provide needed perms - if (pkgManager === 'deno') { - return 'deno run -A npm:create-' - } - // pnpm doesn't support the -- syntax - if (pkgManager === 'pnpm') { - return 'pnpm create ' - } - // For other package managers, preserve the original format - return customCommand.startsWith('npm create -- ') - ? `${pkgManager} create -- ` - : `${pkgManager} create ` - }) - // Only Yarn 1.x doesn't support `@version` in the `create` command - .replace('@latest', () => (isYarn1 ? '' : '@latest')) - .replace(/^npm exec /, () => { - // Prefer `pnpm dlx`, `yarn dlx`, or `bun x` - if (pkgManager === 'pnpm') { - return 'pnpm dlx ' - } - if (pkgManager === 'yarn' && !isYarn1) { - return 'yarn dlx ' - } - if (pkgManager === 'bun') { - return 'bun x ' - } - if (pkgManager === 'deno') { - return 'deno run -A npm:' - } - // Use `npm exec` in all other cases, - // including Yarn 1.x and other custom npm clients. - return 'npm exec ' - }) - ) + let command = customCommand + .replace(/^npm create (?:-- )?/, () => { + // `bun create` uses it's own set of templates, + // the closest alternative is using `bun x` directly on the package + if (pkgManager === 'bun') { + return 'bun x create-' + } + // Deno uses `run -A npm:create-` instead of `create` or `init` to also provide needed perms + if (pkgManager === 'deno') { + return 'deno run -A npm:create-' + } + // pnpm doesn't support the -- syntax + if (pkgManager === 'pnpm') { + return 'pnpm create ' + } + // For other package managers, preserve the original format + return customCommand.startsWith('npm create -- ') + ? `${pkgManager} create -- ` + : `${pkgManager} create ` + }) + // Only Yarn 1.x doesn't support `@version` in the `create` command + .replace('@latest', () => (isYarn1 ? '' : '@latest')) + .replace(/^npm exec /, () => { + // Prefer `pnpm dlx`, `yarn dlx`, or `bun x` + if (pkgManager === 'pnpm') { + return 'pnpm dlx ' + } + if (pkgManager === 'yarn' && !isYarn1) { + return 'yarn dlx ' + } + if (pkgManager === 'bun') { + return 'bun x ' + } + if (pkgManager === 'deno') { + return 'deno run -A npm:' + } + // Use `npm exec` in all other cases, + // including Yarn 1.x and other custom npm clients. + return 'npm exec ' + }) + + if (pkgManager === 'pnpm') { + // `npm exec -- ` uses `--` to split npm flags from package args. `pnpm dlx` doesn't need this separator, and keeping it can break CLIs. + command = command.replace(/^pnpm dlx (\S+) -- /, 'pnpm dlx $1 ') + } + + return command } function getLabel(variant: FrameworkVariant) {