Yarn: Ability to specify location of Node in .yarnrc

Created on 25 Oct 2017  Â·  5Comments  Â·  Source: yarnpkg/yarn

Do you want to request a feature or report a bug?
feature

What is the current behavior?
Yarn only looks for a global instance of Node, while some environments require different versions that are installed locally. Specifying to use a local instance of yarn still results in yarn using whichever global version of node is installed. This creates a lot of issues with other node modules if the global version of node is different than the version used within the project.

What is the expected behavior?
It would be great to be able to specify in .yarnrc the location of the Node version you would like to use. Just like you can specify to use ./bin/yarn, could we specify ./bin/node?

Please mention your node.js, yarn and operating system version.
node v6.10.1
yarn v1.0.1
Linux x64

Most helpful comment

I found a way around this, you just need to modify temporarily the path variable so that the node binaries you want to use and execute yarn commands without allowing linux to change the shell session, this might not be the most elegant solution, but it is functional:

export PATH=/path/to/node/bin:$PATH && yarn command

This worked like a charm, specially in jenkins where you get different node versions from the plugin.

All 5 comments

IMO relying on PATH is the answer here....

What if you have a team? hard coded paths dont work.

if your shipping some app with an expected node, you could just start a script instead that loads your relative path loaded node.

Or if you are trying to target a specific node, use something like nvm

scripts {
start: "nvm blah myapp.js"
}

for example.

In our experience, yarn hasn't respected changes to the PATH.

We encountered this issue in working on deployments that look like:

  • fresh vm
  • yarn/node binaries downloaded locally to ./bin in the project root
  • build process run by makefile, including setting PATH to ./bin

If there is no global version of node installed, yarn simply quits and says it can't find node. For this reason we had to switch to npm which added a ton of time to our deployments.

I found a way around this, you just need to modify temporarily the path variable so that the node binaries you want to use and execute yarn commands without allowing linux to change the shell session, this might not be the most elegant solution, but it is functional:

export PATH=/path/to/node/bin:$PATH && yarn command

This worked like a charm, specially in jenkins where you get different node versions from the plugin.

@juan-ruiz I can see where this would work! I'll give it a try and let you know how it goes.

modifying PATH won't work if you built yarn hermetically:

> node --version; nodejs --version; yarn exec -- node --version
v11.14.0
fish: Unknown command 'nodejs'
yarn exec v1.9.4
v8.11.4
✨  Done in 0.07s.

I'll rebuild yarn locally, but making this configurable would definitely be welcome

Was this page helpful?
0 / 5 - 0 ratings