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

[Bug?]: Yarn doesn't use Node found first in PATH #4658

Closed
1 task
RobbieMcKinstry opened this issue Jul 23, 2022 · 7 comments
Closed
1 task

[Bug?]: Yarn doesn't use Node found first in PATH #4658

RobbieMcKinstry opened this issue Jul 23, 2022 · 7 comments
Labels
bug Something isn't working stale Issues that didn't get attention

Comments

@RobbieMcKinstry
Copy link

RobbieMcKinstry commented Jul 23, 2022

Self-service

  • I'd be willing to implement a fix

Describe the bug

yarn node is using a surprising version of Node. I'm not sure where or when this version was even installed, but it certainly defies my expectations about which version is active. I also can't find a way to change the version used by Yarn, or any documentation of how the executable is selected.

$ yarn --version
3.2.2
$ yarn node --version
v16.13.0
$ node --version
v18.6.0
$ which node
/Users/robbiemckinstry/.volta/bin/node
$ /Users/robbiemckinstry/.volta/bin/node --version
v18.6.0
$ yarn config | grep 'node'
➤ YN0000: defaultLanguageName           'node'
➤ YN0000: nodeLinker                    'pnp'
➤ YN0000: pnpShebang                    '#!/usr/bin/env node'
$ /usr/bin/env node --version
v18.6.0
$ stat /private/var/folders/wl/lpr944fn02v7lhmr6gjjclx00000gn/T/xfs-2b580fed/node
stat: /private/var/folders/wl/lpr944fn02v7lhmr6gjjclx00000gn/T/xfs-e4f51516/node: stat: No such file or directory

To reproduce

# Install Node with Volta.
$ curl https://get.volta.sh | bash
$ volta install [email protected]
$ node --version
# Install Yarn 
$ corepack enable
$ corepack prepare [email protected] --activate
# Add Engine version to package.json
$ cat package.json
{
  "name": "tailwindui-saas",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "browserslist": "defaults, not ie <= 11",
  "dependencies": {
    "@headlessui/react": "^1.6.5",
    "@tailwindcss/forms": "^0.5.2",
    "autoprefixer": "^10.4.7",
    "clsx": "^1.2.0",
    "focus-visible": "^5.2.0",
    "next": "12.2.0",
    "postcss": "^8.4.14",
    "postcss-focus-visible": "^6.0.4",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "tailwindcss": "^3.1.4"
  },
  "devDependencies": {
    "eslint": "8.19.0",
    "eslint-config-next": "12.2.0",
    "prettier": "^2.7.1",
    "prettier-plugin-tailwindcss": "^0.1.11"
  },
  "engines": {
    "node": "18.6.0",
    "yarn": "3.2.2"
  },
  "volta": {
    "node": "18.6.0"
  }
}
# Inspect Yarn Version
$ yarn node --version
v16.13.0
$ node --version
v18.6.0

Environment

System:
    OS: macOS 12.4
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Binaries:
    Node: 16.13.0 - /private/var/folders/wl/lpr944fn02v7lhmr6gjjclx00000gn/T/xfs-2b580fed/node
    Yarn: 3.2.2 - /private/var/folders/wl/lpr944fn02v7lhmr6gjjclx00000gn/T/xfs-2b580fed/yarn
    npm: 8.6.0 - ~/.volta/tools/image/npm/8.6.0/bin/npm

Additional context

This issue is tangentially related to #1177
I would expect yarn node to use the node version provided in the engine.node field of package.json, or to throw a warning if the version it's using does not match.

@RobbieMcKinstry RobbieMcKinstry added the bug Something isn't working label Jul 23, 2022
@yarnbot

This comment was marked as outdated.

@yarnbot yarnbot added the stale Issues that didn't get attention label Aug 22, 2022
@merceyz
Copy link
Member

merceyz commented Aug 22, 2022

I also can't find a way to change the version used by Yarn, or any documentation of how the executable is selected.

To quote the documentation for yarn node:

The Node process will use the exact same version of Node as the one used to run Yarn itself
https://yarnpkg.com/cli/node

@RobbieMcKinstry
Copy link
Author

That seems to contradict the results I'm seeing. From my second and third commands:

$ yarn node --version
v16.13.0
$ node --version
v18.6.0

@merceyz
Copy link
Member

merceyz commented Sep 4, 2022

You'll have to debug your system to figure out why yarn is spawned by a different version of node than the one you expect.
yarn node uses process.execPath so the version of node is out of its control.

@merceyz merceyz closed this as not planned Won't fix, can't repro, duplicate, stale Sep 4, 2022
@RobbieMcKinstry
Copy link
Author

I'm afraid I still don't understand.
How could it be possible that process.execPath returns a different path than which node? By definition these should point to the same filesystem path -- the first instance of an executable file named node found within $PATH.

@RobbieMcKinstry
Copy link
Author

Hello! Could we reopen this issue? I don't feel like my original question has been addressed. It seems to defy logic that the following two conditions could be simultaneous true:

  1. yarn node uses process.execPath

  2. I'm seeing this output on my system:

$ yarn node --version
v16.13.0
$ node --version
v18.6.0

@merceyz
Copy link
Member

merceyz commented Oct 7, 2022

How could it be possible that process.execPath returns a different path than which node? By definition these should point to the same filesystem path -- the first instance of an executable file named node found within $PATH.

Not necessarily, have you tried running yarn node -p process.execPath to see which node binary is spawning Yarn?
My assumption is that you have some old node install / leftovers on your system that is used instead of what you're expecting.

Hello! Could we reopen this issue?

I don't see anything actionable to justify reopening, the node binary used to spawn Yarn is out of our control.

I tried the provided reproduction the last time I commented on this issue and again now, it fails on

$ corepack enable
bash: corepack: command not found

If I follow volta-cli/volta#987 (comment) it passes as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale Issues that didn't get attention
Projects
None yet
Development

No branches or pull requests

3 participants