Skip to content

Vite+ and corepack-like functionality #1309

@rChaoz

Description

@rChaoz

Describe the bug

TL;DR Using Vite+ without an existing Node installation means no corepack, so any scripts/commands that try to run pnpm/yarn fail. Corepack can be installed, but will manage its own versions of pnpm/yarn, same as Vite+, leading to differences between running pnpm i and vp i.

Also, this is a little bit of a dupe of #858 (sorry, didn't see it before opening this 😞), but I think this issue better explains the problem & proposes a better solution.


I tried cloning the vite-plus repo according to the contribution guide with just init, and I've encountered some problems. I decided to document this here as I think it has some value regarding vp as a full-featured tool for everything JS-related, which seems to be its goal, and does very well at it too.

I'll start by saying that I removed nvm and associated global node installations first, to rely only on vp env. The issue described here is encountered by anyone that uses vp env for managing Node, without an existing node installation.

just init tries to run pnpm install, but fails with:

Error: Command failed: pnpm install --no-frozen-lockfile
'pnpm' is not recognized as an internal or external command, operable program or batch file.

Makes sense, since it downloaded a new node version. Normally, I'd enable corepack when I see this, but this doesn't work:

> corepack enable
corepack: The term 'corepack' is not recognized as a name of a cmdlet, function, script file, or executable program.
> npm list -g
C:\Users\Matei\.vite-plus\js_runtime\node\24.14.1
+-- corepack@0.34.6
`-- npm@11.11.0

Corepack is there, but Vite+ did not create a shim for it in ~/.vite-plus/bin. Vite+ does create shims for global packages, when using npm i -g or vp i -g. But since corepack comes preinstalled with node, this never happens.

Note: Both npm i -g and vp i -g, from my understanding, install a package globally, but for a specific node version. yarn ... will always run on the Node version I installed it with, not the dynamic Node version (based on .node-version or package.json#engines). It will remain stuck on whatever node version I happened to be using, which does depend on CWD, .node-version etc., forever. This seems like a potential design flaw, but I may be wrong, and regardless it's not related to the current issue. I thought it was worth pointing out, especially since it's not documented.

Continuing, the problem is that trying to call package managers directly, which relies on corepack, doesn't work out of the box. This includes vite-plus itself, as it runs pnpm directly. This can be fixed easily, however, by running:

vp i -g corepack

This works, but IMO is not "clean". Corepack now downloads and manages package manager versions independently of Vite+, so depending on whether you use vp add or pnpm add, a different installation (which may or may not be the same version) is used, as well as with a different node version.

My suggestions to address this, the first one being IMO the best:

  • Vite+ should implement corepack capabilities itself. It already does this when using vp i, vp add etc., which install and run the correct package manager and version automatically. The only piece missing is shimming the actual yarn, pnpm etc. executables by default.
  • If not, at least include some documentation on its environment page that corepack is not available by default, and vp install, vp add etc. should be used instead. However, I do think some people will be turned away by this - some people will simply not want to adjust their workflows (scripts, muscle memory) to use vp instead of pnpm.

If this is out of scope, and vp only wants to support managing package managers for its own commands, then:

  • Document on its environment page that corepack is not available by default, and that it should be installed with vp install -g corepack. Even as Node will no longer come with corepack by default from now on, this information would still be useful.
  • Automatically run vp install -g corepack when installing vp, or an equivalent.

Reproduction

  1. Make sure there is no global Node installation and you're only relying on vp env
  2. Try to clone/work on any repo which uses pnpm/yarn commands

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions