stackblitz / webcontainer-core

Dev environments. In your web app.
https://webcontainers.io
MIT License
3.95k stars 176 forks source link

Codeflow: pnpm version is a little outdated on vite-plugin-svelte #861

Closed sylwiavargas closed 2 years ago

sylwiavargas commented 2 years ago

Describe the bug

From Dominik: in @sveltejs/vite-plugin-svelte we use a pretty recent version of pnpm and renovate-bot helps us keeping it up2date. our package.json currently has

  "packageManager": "pnpm@7.13.1",
  "engines": {
    "pnpm": "^7.13.1",

which leads to

~/sveltejs/vite-plugin-svelte pr/benmccann/459
❯ pnpm i
 ERR_PNPM_UNSUPPORTED_ENGINE  Unsupported environment (bad pnpm and/or Node.js version)

Your pnpm version is incompatible with "/home/sveltejs/vite-plugin-svelte".

Expected version: ^7.13.1
Got: 7.13.0

This is happening because the package's manifest has an engines.pnpm field specified.
To fix this issue, install the required pnpm version globally.

To install the latest version of pnpm, run "pnpm i -g pnpm".
To check your pnpm version, run "pnpm -v".

~/sveltejs/vite-plugin-svelte pr/benmccann/459
❯ pnpm i -g pnpm
 ERROR  Unable to find the global bin directory
Run "pnpm setup" to create it automatically, or set the global-bin-dir setting, or the PNPM_HOME env variable. The global bin directory should be in the PATH.

~/sveltejs/vite-plugin-svelte pr/benmccann/459

Link to the blitz that caused the error

https://stackblitz.com/~/github.com/sveltejs/vite-plugin-svelte

Steps to reproduce

  1. Run https://stackblitz.com/~/github.com/sveltejs/vite-plugin-svelte

Expected behavior

Dependency installation

Parity with Local

Screenshots

No response

Platform

No response

Additional context

No response

dominikg commented 2 years ago

We use the package.json packageManager field to declare the version we prefer to use and an engine restriction to ensure it.

https://github.com/sveltejs/vite-plugin-svelte/blob/74fd16db25d0be6c624e3d7e77b170ff7afb34ed/package.json#L58

If webcontainer can't provide the latest pnpm version, we may be able to relax the engine restriction a bit, but ideally it would be great if webcontainer could detect the existance of packageManager and honor that, which would be similar to a user having corepack enabled.

https://nodejs.org/api/packages.html#packagemanager https://nodejs.org/api/corepack.html

Running corepack inside webcontainer might not be feasible, but you can do it without by simply parsing packageManager and fetching the version from npm registry as well: https://github.com/sveltejs/vite-plugin-svelte/blob/74fd16db25d0be6c624e3d7e77b170ff7afb34ed/.github/workflows/ci.yml#L46-L48

dominikg commented 2 years ago

While this issue only touches pnpm, i think it also applies to yarn (does that work in webcontainers at all?) and npm if there is a packageManager/engine combo for that in the repo.

SamVerschueren commented 2 years ago

@dominikg we currently ship pnpm@7.13.0 and try to stay close to the latest version. I think we usually wait a bit to make sure there are no breaking bugs on the pnpm side. Is there a reason that 7.13.1 is needed for that package?

We recently shipped updates regarding yarn. But we currently only support yarn v1 officially.

dominikg commented 2 years ago

we use renovate-bot to keep our dependencies updated and it bumps the engine restriction alongside the packageManager field:

eg https://github.com/sveltejs/vite-plugin-svelte/pull/466/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519R60

Our CI automatically installs and uses the version in packageManager.

There is no absolute need for using the latest version, but we prefer keeping everyone on the same version and updating it regularly. If webcontainers only support a single version of pnpm and that is behind latest, is there a way to follow the version you support?

SamVerschueren commented 2 years ago

We've updated pnpm to the latest version (7.13.6) and it now seems to work again 👍 .