[Bug?]: `yarn run` changes the path to node while executing a script
Self-service
- [ ] I'd be willing to implement a fix
Describe the bug
While yarn run is running the which node will resolve to a temporary location, so if the command is recording the location of Node.js executable it will record a wrong path.
This happens when working with React Native and running scripts from package.json which run CocoaPods. The RN CocoaPods script will record the location of Node.js for Xcode, because Xcode could be started from macOS UI and it won't have the correct environment. And then Xcode will fail to build the app, because the build script won't find the node in the tmp dir.
To reproduce
Reproducible on both macOS and Linux.
I rechecked on Linux VM just to make sure the starting conditions are cleaner.
package.json
{
"name": "test-yarn",
"version": "1.0.0",
"packageManager": "[email protected]",
"main": "index.js",
"license": "MIT",
"scripts": {
"env": "echo \"export NODE_BINARY=$(which node)\"",
}
}
> yarn env
export NODE_BINARY=/tmp/xfs-9b6cb3be/node
Environment
System:
OS: Linux 5.10 Debian GNU/Linux 11 (bullseye) 11 (bullseye)
CPU: (2) x64 Intel Xeon Processor (Skylake, IBRS)
Binaries:
Node: 18.13.0 - /tmp/xfs-db85403f/node
Yarn: 4.1.0 - /tmp/xfs-db85403f/yarn
npm: 8.19.3 - ~/.nvm/versions/node/v18.13.0/bin/npm
Additional context
Yarn is installed by corepack enable - maybe that is an important factor 🤔
This doesn't happen when running the same script with NPM 😅
Update: Not necessary a corepack enable thing, because running the same script with pnpm is fine:
> pnpm run env
> [email protected] env /home/al/test-yarn
> echo "export NODE_BINARY=$(which node)"
export NODE_BINARY=/home/al/.nvm/versions/node/v18.13.0/bin/node