Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PNPM is not using the node version set via pnpm env use #4203

Closed
bestickley opened this issue Jan 6, 2022 · 28 comments · Fixed by #4780
Closed

PNPM is not using the node version set via pnpm env use #4203

bestickley opened this issue Jan 6, 2022 · 28 comments · Fixed by #4780

Comments

@bestickley
Copy link

bestickley commented Jan 6, 2022

pnpm version: 6.25.0

Code to reproduce the issue:

.npmrc

engine-strict = true

Slice of package.json

"engines": {
    "node": ">=16"
  },
❯ pnpm env use --global 16
Node.js 16.13.1 is activated
  /Users/stickb/Library/pnpm/node -> /Users/stickb/Library/pnpm/nodejs/16.13.1/bin/node
❯ pnpm i
 ERR_PNPM_UNSUPPORTED_ENGINE  Unsupported environment (bad pnpm and/or Node.js version)

Your Node version is incompatible with "/Users/stickb/Code/green-boost".

Expected version: >=16
Got: v14.18.2

This is happening because the package's manifest has an engines.node field specified.
To fix this issue, install the required Node version.
❯ node -v
v16.13.1

Expected behavior:

pnpm should use version of node that it set

Actual behavior:

pnpm uses another version of Nodejs

Additional information:

  • node -v prints: 16.13.1
  • Windows, macOS, or Linux?: macOS
@PabloSzx
Copy link
Member

@bestickley what happens if you do pnpm add -g pnpm after doing pnpm env use --global 16

@bestickley
Copy link
Author

@PabloSzx, this worked! Thank you very much.
Documenting output here:

❯ node -v
v14.18.2
❯ pnpm env use --global 16
Node.js 16.13.2 is activated
  /Users/stickb/Library/pnpm/node -> /Users/stickb/Library/pnpm/nodejs/16.13.2/bin/node
❯ pnpm i
 ERR_PNPM_UNSUPPORTED_ENGINE  Unsupported environment (bad pnpm and/or Node.js version)

Your Node version is incompatible with "/Users/stickb/Code/green-boost".

Expected version: >=16
Got: v14.18.2

This is happening because the package's manifest has an engines.node field specified.
To fix this issue, install the required Node version.
❯ pnpm add -g pnpm
Nothing to stop. No server is running for the store at /Users/stickb/.pnpm-store/v3
gb-cli is linked to /Users/stickb/Library/pnpm/nodejs/14.18.2/pnpm-global/5/node_modules from /Users/stickb/Code/green-boost/packages/gb-cli
gb-lib is linked to /Users/stickb/Library/pnpm/nodejs/14.18.2/pnpm-global/5/node_modules from /Users/stickb/Code/green-boost/packages/gb-lib
Packages: +2
++
Progress: resolved 211, reused 210, downloaded 1, added 2, done

/Users/stickb/Library/pnpm/nodejs/14.18.2/pnpm-global/5:
+ pnpm 6.26.1
❯ pnpm i
Scope: all 4 workspace projects
Lockfile is up-to-date, resolution step is skipped
Already up-to-date
❯ pnpm -v
6.26.1

@zkochan
Copy link
Member

zkochan commented Jan 14, 2022

I think it should still work without running pnpm i -g pnpm

@zkochan zkochan reopened this Jan 14, 2022
@bestickley
Copy link
Author

Agreed, I thought an update to the pnpm was made to fix this. Thanks for reopening.

@gquinteros93
Copy link

I had the same issue as @bestickley and I was able to fix it thanks to @PabloSzx comment (thanks 👏 ):

do pnpm add -g pnpm after doing pnpm env use --global 16

Error:

Your Node version is incompatible with "/Users/germanquinteros/...".

Expected version: 16.x
Got: v14.17.0

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

Environment:

nvm: 0.38.0
node: v16.13.2
pnpm: 6.30.0

.npmrc

always-auth=true
engine-strict=true
shamefully-hoist=true
enable-pre-post-scripts=true

package.json

  "engines": {
    "node": "16.x"
  },

@stychu
Copy link

stychu commented Apr 19, 2022

I experienced this issue right now.
After upgrading from node v14 to v16 via nvm I was unable to do pnpm install.

Got the same error

...
Expected version: >=16
Got: v14.18.2

After doing pnpm add -g pnpm I can install dependencies.

@gunta
Copy link

gunta commented Apr 20, 2022

Same here, wonder why pnpm i -g pnpm is necessary.

@stychu
Copy link

stychu commented Apr 26, 2022

Seems like pnpm is being bundled to a given node version or smth? I use 14.18.1 node but when I install pnpm it is bundled with 14.17.0 which prevents the installation due to the engines restriction.

@lildeadprince
Copy link

lildeadprince commented May 6, 2022

Found this issue, while experiencing some shenanigans in the way how the env command and Node usage works.

My environment

node -v = v18.0.0
pnpm env use -g 16
package.engine.node = ">=17"

Set engine to 17+ so that it will always WARN, except when using global node installation, which seems to be just never)

Use as command (OK)

If I run dependency command as a command myself, then as a non-nested command it will run with Node 16 from env. Works as expected so far.

$ pnpm simple-git-hooks
 WARN  Unsupported engine: wanted: {"node":">=17"} (current: {"node":"v16.15.0","pnpm":"7.0.0"})
...

Use as nested script (uses bundled?)

Now I nest that in a package script to run after install:
package.scripts.prepare = "pnpm simple-git-hooks"

It results in:

$ pnpm run prepare
 WARN  Unsupported engine: wanted: {"node":">=17"} (current: {"node":"v16.15.0","pnpm":"7.0.0"})

> app@0.1.0 prepare C:\Users\...
> pnpm simple-git-hooks

 WARN  Unsupported engine: wanted: {"node":">=17"} (current: {"node":"v14.17.0","pnpm":"7.0.0"})
...

pnpm uses the Node from env itself, but then nested script is run with it seems bundled Node version (I do not have 14.17.0 installed anywhere by myself) even instead of one available as global node command

@kissu
Copy link

kissu commented May 8, 2022

I did not achieved to solve this issue even if nvm was using v16 properly (PNPM complaining about being stuck at node 12).
Uninstalled and re-installed it properly with Corepack and now it's working great.

PS: Wasn't working with a curl reinstall neither (was using node 14 for some reason while I had a engine version specified in my package.json)

@gunta
Copy link

gunta commented May 19, 2022

Related/Duplicated: #4409
Related/Duplicated: #3673

This happens in both CI and local.

@Deebster
Copy link

Deebster commented May 20, 2022

I cannot get past this error, even though I uninstalled node and pnpm, rebooted, then reinstalled pnpm and used pnpm env use --global 18 to install node and rebooted once more (since pnpm 7 seems to have issues with env paths).

PowerShell 7.2.3

PS C:\code\svelte\pwa-demo> pnpm add -D @sveltejs/adapter-cloudflare-workers
 ERR_PNPM_UNSUPPORTED_ENGINE  Unsupported environment (bad pnpm and/or Node.js version)  

Your Node version is incompatible with "registry.npmjs.org/@sveltejs/kit/1.0.0-next.336".

Expected version: >=16
Got: v14.17.0

This is happening because the package's manifest has an engines.node field specified.     
To fix this issue, install the required Node version.
Progress: resolved 12, reused 12, downloaded 0, added 0
PS C:\code\svelte\pwa-demo> node -v
v18.2.0
PS C:\code\svelte\pwa-demo> where.exe node
C:\Users\micro\AppData\Local\pnpm\node.exe
PS C:\code\svelte\pwa-demo> & C:\Users\micro\AppData\Local\pnpm\node.exe -v
v18.2.0
PS C:\code\svelte\pwa-demo> pnpm -v
7.1.2
PS C:\code\svelte\pwa-demo> pnpm add -g pnpm
Nothing to stop. No server is running for the store at C:\Users\micro\AppData\Local\pnpm\store\v3
 WARN  deprecated rollup-plugin-inject@3.0.2: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-inject.
Already up-to-date
Progress: resolved 77, reused 57, downloaded 0, added 0, done
PS C:\code\svelte\pwa-demo> pnpm add -D @sveltejs/adapter-cloudflare-workers      
 ERR_PNPM_UNSUPPORTED_ENGINE  Unsupported environment (bad pnpm and/or Node.js version)   

Your Node version is incompatible with "registry.npmjs.org/@sveltejs/kit/1.0.0-next.336". 

Expected version: >=16
Got: v14.17.0

This is happening because the package's manifest has an engines.node field specified.     
To fix this issue, install the required Node version.
Progress: resolved 13, reused 13, downloaded 0, added 0`

edit: I've gone back to npm for now; I can't afford to spend any more time on v7 issues

@zkochan
Copy link
Member

zkochan commented May 20, 2022

At the moment, I don't really have ideas why this doesn't work (maybe we can add some more debug information to the error message).

Also, I think as a workaround, you may put an .npmrc to the root of your project with the following configuration:

use-node-version=18.2.0

NOTE: You should use an exact version for this setting.

@Deebster
Copy link

Deebster commented May 22, 2022

@zkochan the reported version appears to be from the pnpm.exe binary.

I've just done another clean install of pnpm on Win10 and tried your fix:

PS C:\code\svelte> node -v
v18.2.0
PS C:\code\svelte> pnpm -v
7.1.3
PS C:\code\svelte> pnpm create svelte@next test
// snip
PS C:\code\svelte> cd test
PS C:\code\svelte\test> pnpm i
 ERR_PNPM_UNSUPPORTED_ENGINE  Unsupported environment (bad pnpm and/or Node.js version)

Your Node version is incompatible with "registry.npmjs.org/@sveltejs/kit/1.0.0-next.338". 

Expected version: >=16
Got: v14.17.0

This is happening because the package's manifest has an engines.node field specified.     
To fix this issue, install the required Node version.
Progress: resolved 2, reused 0, downloaded 1, added 0

// I add use-node-version=18.2.0 to .npmrc
PS C:\code\svelte\test> pnpm i
// identical error

However, despite that %PNPM_HOME%\pnpm.exe -v gives 7.1.3, the version info talks about Node 14.17.0:

PS C:\code\svelte\test> Get-ChildItem $Env:PNPM_HOME\pnpm.exe | Format-List -Property VersionInfo

VersionInfo : File:             C:\Users\micro\AppData\Local\pnpm\pnpm.exe
              InternalName:     node
              OriginalFilename: node.exe
              FileVersion:      14.17.0
              FileDescription:  Node.js JavaScript Runtime
              Product:          Node.js
              ProductVersion:   14.17.0
              Debug:            False
              Patched:          False
              PreRelease:       False
              PrivateBuild:     False
              SpecialBuild:     False
              Language:         English (United States)

@zkochan
Copy link
Member

zkochan commented May 22, 2022

@Deebster I see. I was able to reproduce it as well. I'll look into it.

@bur3ku
Copy link

bur3ku commented Jun 5, 2022

today I needed to do this:
corepack enable
corepack prepare pnpm@<version> --activate
pnpm env use --global <version>
then pnpm i worked after npm init svelte my-app

@beeb
Copy link

beeb commented Jun 21, 2022

The problem is still happening for me on 7.3.0. Had to globally install pnpm after setting the env setting, like @PabloSzx suggested.

@JakeCooper
Copy link

Confirmed also happening for us, and the env setting is required to be set

@zkochan
Copy link
Member

zkochan commented Jul 2, 2022

Sorry, the initial issue was fixed, so you need to create a new issue with exact steps to reproduce.

@keleus
Copy link

keleus commented Jul 10, 2022

If you use the https://get.pnpm.io/install script to install pnpm, you will need to uninstall and reinstall pnpm after changing node versions.

@itzomen
Copy link

itzomen commented Oct 24, 2022

I'm currently facing this issue

node -v
# v16.18.0
pnpm -v
#7.14.0
pnpm doctor
WARN  Load npm builtin configs failed. If the prefix builtin config does not work, you can use "pnpm config ls" to show builtin configs. And then use "pnpm config --global set <key> <value>" to migrate configs from builtin to global.

nvlgzr added a commit to nvlgzr/ouroboros that referenced this issue Dec 13, 2022
Vercel Error:
 ERR_PNPM_UNSUPPORTED_ENGINE  Unsupported environment (bad pnpm and/or Node.js version)
Your Node version is incompatible with "/@sveltejs/kit/1.0.0-next.520_svelte@3.47.0+vite@3.1.8".
Expected version: >=16.14
Got: v14.21.1

Hoping this advice does the trick: pnpm/pnpm#4203 (comment)
@pete-willard
Copy link

pete-willard commented Jan 26, 2023

The same happened to me on pnpm v7.26.0. I am on Manjaro Linux. I must have had node v14 installed via nvm at some point. Setting the exact node version in .npmrc helped. Installing pnpm -g also helped.

@bradyab
Copy link

bradyab commented Mar 16, 2023

none of these solutions worked for me, I ended up simply installing the right node version on my machine with n <version>

@TheVexy
Copy link

TheVexy commented Apr 2, 2023

Same issue for me
~ pnpm add -g pnpm Nothing to stop. No server is running for the store at /home/felix/.local/share/pnpm/store/v3 Already up to date Progress: resolved 1, reused 1, downloaded 0, added 0, done Done in 1.4s
pnpm env use --global 18 Fetching Node.js 18.15.0 ... Node.js 18.15.0 is activated
pnpm install [sudo] password for felix:  WARN  Unsupported engine: wanted: {"node":">=18"} (current: {"node":"v16.17.0","pnpm":"8.1.0"})

update: this fixed it for me ! #5266 (comment)

@Jwefro
Copy link

Jwefro commented Jun 13, 2023

pnpm store prune && pnpm i

@silasabbott
Copy link

None of the other solutions here worked for me, but adding this line to my .npmrc file did fix it:

use-node-version=18.19.0

@depsimon
Copy link

depsimon commented Jan 8, 2024

None of the other solutions here worked for me, but adding this line to my .npmrc file did fix it:

use-node-version=18.19.0

Fixed it for me in my monorepo using Volta.

Seems like the volta node is used at the root, but the global node is used for apps & packages.
use-node-version seems to force it for everything.

@thevuong
Copy link

After installing pnpm via brew, run the pnpm setup command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.