Upgrading node and yarn

Problem

You are getting the following error when trying to use yarn:

$ yarn
yarn install v1.21.1
[1/5] Validating package.json...
error xxxxx@: The engine "node" is incompatible with this module. Expected version "^10.0.0". Got "8.10.0"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

Solution

Upgrade yarn

$ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
[sudo] password for username: 
OK

$ echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
deb https://dl.yarnpkg.com/debian/ stable main

$ sudo apt-get update
$ sudo apt-get upgrade

Which should give the updated yarn version:

$ yarn
yarn install v1.22.5
[1/5] Validating package.json...
error xxxxx@: The engine "node" is incompatible with this module. Expected version "^10.0.0". Got "8.10.0"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

Upgrade node version with the correct version from above (ie 10.0.0)

$ curl -fsSL https://deb.nodesource.com/setup_10.x | sudo -E bash -

$ sudo apt-get install -y nodejs
....
The following packages will be upgraded:
  nodejs
...

And then the needed versions would have been installed:

$ yarn
yarn install v1.22.5
[1/5] Validating package.json...
[2/5] Resolving packages...
success Already up-to-date.
Done in 0.90s.