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 2 should run child processes with the same Node #1766

Closed
1 task
segrey opened this issue Aug 26, 2020 · 10 comments
Closed
1 task

[Bug] Yarn 2 should run child processes with the same Node #1766

segrey opened this issue Aug 26, 2020 · 10 comments
Labels
bug Something isn't working

Comments

@segrey
Copy link
Contributor

segrey commented Aug 26, 2020

  • I'd be willing to implement a fix

Describe the bug

Actual: Yarn 2 uses node from PATH when executing yarn node ...
Expected: Yarn 2 should use the Node that is running Yarn itself when executing yarn node ...

To Reproduce

Configure Yarn 2.1.1:

yarn set version berry
yarn set version 2.1.1
$ yarn --version
2.1.1
$ node --version
v14.8.0
$ ~/.nvm/versions/node/v14.8.0/bin/node /usr/share/yarn/bin/yarn.js node -e "console.log(process.version)"
v14.8.0
$ ~/.nvm/versions/node/v12.16.1/bin/node /usr/share/yarn/bin/yarn.js node -e "console.log(process.version)"
v14.8.0

Expected output of the last command is v12.16.1

Works as expected with Yarn 1:

$ yarn --version
1.22.4
$ node --version
v14.8.0
$ ~/.nvm/versions/node/v14.8.0/bin/node /usr/share/yarn/bin/yarn.js node -e "console.log(process.version)"
yarn node v1.22.4
v14.8.0
Done in 0.05s.
$ ~/.nvm/versions/node/v12.16.1/bin/node /usr/share/yarn/bin/yarn.js node -e "console.log(process.version)"
yarn node v1.22.4
v12.16.1
Done in 0.04s.

Environment if relevant (please complete the following information):

  • OS: Linux
  • Node version 12.16.1, 14.8.0
  • Yarn version 1.22.4, 2.1.1

Additional context

There is an unpleasant consequence: when node is not in PATH, yarn node ... cannot be run:

$ nvm deactivate
/home/segrey/.nvm/*/bin removed from ${PATH}
$ node --version

Command 'node' not found, but can be installed with:

sudo apt install nodejs

$ ~/.nvm/versions/node/v14.8.0/bin/node /usr/share/yarn/bin/yarn.js node -e "console.log(process.version)"
/usr/bin/env: ‘node’: No such file or directory

This caused https://youtrack.jetbrains.com/issue/WEB-46371.

@segrey segrey added the bug Something isn't working label Aug 26, 2020
@segrey
Copy link
Contributor Author

segrey commented Aug 26, 2020

Looks like a regression (#502). @arcanis

@merceyz
Copy link
Member

merceyz commented Aug 26, 2020

Thought we fixed this in #1403 🤔

@segrey
Copy link
Contributor Author

segrey commented Aug 26, 2020

@merceyz Ooops, I'm sorry, actually the issue targeted Yarn version 2.1.1-git.20200806.1b11fbd5 (version from https://github.com/facebook/jest as of now), not Yarn 2.1.1.
It works correctly with Yarn 2.1.1, closing. Nope it works correctly with yarn set version berry which reports 2.1.1 as yarn --version. But it fails if yarn updated with yarn set version 2.1.1.

@segrey segrey closed this as completed Aug 26, 2020
@merceyz
Copy link
Member

merceyz commented Aug 26, 2020

2.1.1-git.20200806.1b11fbd5 is newer than 2.1.1 so if it doesn't work with that it's a regression

@merceyz merceyz reopened this Aug 26, 2020
@segrey
Copy link
Contributor Author

segrey commented Aug 26, 2020

Interestingly, it works correctly after yarn set version berry, but fails after yarn set version 2.1.1. Both yarn installations report version 2.1.1 (is it ok?).
@merceyz Which one is newer?

$ yarn --version
1.22.4
$ node --version
v14.8.0
$ ~/.nvm/versions/node/v12.16.1/bin/node /usr/share/yarn/bin/yarn.js node -e "console.log(process.version)"
yarn node v1.22.4
warning package.json: No license field
v12.16.1
Done in 0.12s.
$ yarn set version berry
warning package.json: No license field
Resolving berry to a url...
Downloading https://github.com/yarnpkg/berry/raw/master/packages/berry-cli/bin/berry.js...
Saving it into /home/segrey/samples/pnp/eslint-pnp-example/.yarn/releases/yarn-berry.js...
Updating /home/segrey/samples/pnp/eslint-pnp-example/.yarnrc.yml...
Done!
$ yarn --version
2.1.1
$ ~/.nvm/versions/node/v12.16.1/bin/node /usr/share/yarn/bin/yarn.js node -e "console.log(process.version)"
v12.16.1
$ yarn set version 2.1.1
➤ YN0000: Downloading https://github.com/yarnpkg/berry/raw/%40yarnpkg/cli/2.1.1/packages/yarnpkg-cli/bin/yarn.js
➤ YN0000: Saving the new release in .yarn/releases/yarn-2.1.1.cjs
➤ YN0000: Done in 0.89s
$ yarn --version
2.1.1
$ ~/.nvm/versions/node/v12.16.1/bin/node /usr/share/yarn/bin/yarn.js node -e "console.log(process.version)"
v14.8.0

@merceyz
Copy link
Member

merceyz commented Aug 26, 2020

They should both be the same

@segrey
Copy link
Contributor Author

segrey commented Aug 26, 2020

@merceyz You're right, they are the same. Looks like this issue is caused by .cjs extension, everything works fine with .js extension:

$ yarn set version berry
warning package.json: No license field
Resolving berry to a url...
Downloading https://github.com/yarnpkg/berry/raw/master/packages/berry-cli/bin/berry.js...
Saving it into /home/segrey/samples/pnp/eslint-pnp-example/.yarn/releases/yarn-berry.js...
Updating /home/segrey/samples/pnp/eslint-pnp-example/.yarnrc.yml...
Done!

$ ~/.nvm/versions/node/v12.16.1/bin/node /usr/share/yarn/bin/yarn.js node -e "console.log(process.version)"
v12.16.1

$ mv .yarn/releases/yarn-berry.js .yarn/releases/yarn-berry.cjs 

$ sed -i 's/yarn-berry.js/yarn-berry.cjs/g' .yarnrc.yml 

$ ~/.nvm/versions/node/v12.16.1/bin/node /usr/share/yarn/bin/yarn.js node -e "console.log(process.version)"
v14.8.0

@merceyz
Copy link
Member

merceyz commented Aug 26, 2020

Ah, that's a issue in how V1 spawns Yarn. It was fixed in yarnpkg/yarn#8144 but the CI is broken for V1 so it hasn't been released yet

@merceyz merceyz closed this as completed Aug 26, 2020
@merceyz
Copy link
Member

merceyz commented Aug 27, 2020

The fix has been released in V1, update your global Yarn version and the .cjs extension shouldn't be a problem anymore

@segrey
Copy link
Contributor Author

segrey commented Aug 27, 2020

@merceyz It works now correctly. Thank you!

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

No branches or pull requests

2 participants