I'm attempting to install yarn using npm, as is recommended by the yarn project itself. At first I tried running npm install --global yarn, which failed due to inadequate permissions, so I tried again with sudo npm install --global yarn.
But that gave me the following result:
npm info it worked if it ends with ok
npm verb cli [ '/usr/bin/node',
npm verb cli '/usr/bin/npm',
npm verb cli 'install',
npm verb cli '--verbose',
npm verb cli '--global',
npm verb cli 'yarn' ]
npm info using npm@6.14.4
npm info using node@v10.19.0
npm verb npm-session 92d2a6de56a6da3f
npm http fetch GET 304 https://registry.npmjs.org/yarn 194ms (from cache)
npm timing stage:loadCurrentTree Completed in 249ms
npm timing stage:loadIdealTree:cloneCurrentTree Completed in 1ms
npm timing stage:loadIdealTree:loadShrinkwrap Completed in 2ms
npm timing stage:loadIdealTree:loadAllDepsIntoIdealTree Completed in 3ms
npm timing stage:loadIdealTree Completed in 7ms
npm timing stage:generateActionsToTake Completed in 7ms
npm verb correctMkdir /root/.npm/_locks correctMkdir not in flight; initializing
npm verb lock using /root/.npm/_locks/staging-3a08f0df5026584d.lock for /usr/local/lib/node_modules/.staging
npm timing action:extract Completed in 75ms
npm info lifecycle yarn@1.22.10~preuninstall: yarn@1.22.10
npm info lifecycle yarn@1.22.10~uninstall: yarn@1.22.10
npm verb unbuild rmStuff yarn@1.22.10 from /usr/local/lib/node_modules
npm info lifecycle yarn@1.22.10~postuninstall: yarn@1.22.10
npm timing action:unbuild Completed in 6ms
npm timing action:remove Completed in 6ms
npm timing action:finalize Completed in 2ms
npm timing action:refresh-package-json Completed in 5ms
npm info lifecycle yarn@1.22.10~preinstall: yarn@1.22.10
> yarn@1.22.10 preinstall /usr/local/lib/node_modules/yarn
> :; (node ./preinstall.js > /dev/null 2>&1 || true)
The command exits with exit code 1. The same result occurs in an sudo -i shell. I added the --verbose flag to try to see what's going on, but there's still no discernible error message. And sure enough, yarn isn't installed when I try to run it or use which on it. I also checked ~/.npm/_logs and there are no logs for this error, only logs for the permission errors I encountered when I tried to run it without sudo. Why is this failing?
Using Ubuntu 20.04 LTS.
Edit:
I was able to find the relevant log file in /root/.npm/_logs. It showed this as the error message:
error Cannot find module './get-uid-gid.js'
How do I fix that?