2

I've recently downloaded WSL on my system as well as Ubuntu 20.04 LTS.

I installed Node JS on it and it seems to work fine. But when I tried installing yarn from the following command:

curl -o- -L https://yarnpkg.com/install.sh | bash

It installed yarn 1.22.5 and when I ran yarn --version, it returned 1.22.5

But when I changed the directory to /mnt/c/Users/user-name and tried running yarn --version, it threw this error:

internal/modules/cjs/loader.js:888
  throw err;
  ^

Error: Cannot find module '/mnt/c/users/user-name/C:\Users\user-name\.yarn\releases\yarn-1.22.10.cjs'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:885:15)
    at Function.Module._load (internal/modules/cjs/loader.js:730:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)      
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Is there any way to fix this?

I found a solution to this:

Check this page out. Click on Alternatives and select the operating system Debian / Ubuntu and version Classic Stable (1.22.5).

You can follow the given instructions to install yarn from the Debian package repository, then have a look at the Path Setup section. Follow the instructions given there and yarn will be available globally!

Then you can run yarn --version any where in you're Ubuntu shell and it should be working just fine!

  • At first glance, this appears to likely be a Windows path problem in WSL. Do you have the Windows version of node installed with yarn also? What does `which yarn` give you (in each directory -- the one where it works, and the one where it fails)? Also, looking at your path may be helpful. – NotTheDr01ds Jun 24 '21 at 06:45
  • In the directory where yarn works, `which yarn` returns `/home/user-name/.yarn/bin/yarn` and in the directory where yarn doesn't work, `which yarn` returns `/home/user-name/.yarn/bin/yarn`. It returns the same in both the directories. Can you help me with the PATH in WSL. – Rugved Tipare Jun 24 '21 at 08:11
  • (1) `echo $PATH` for starters. By default, WSL appends the Windows path, so that you can easily access Windows executables. However, sometimes this gets in the way. Do you see anything unusual in there? (2) Also confirm that there isn't a single "period" anywhere in the path. (3) I should have also recommended `which node`. If that still returns something in the Linux filesystem, then it's probably not the problem I was originally thinking. – NotTheDr01ds Jun 24 '21 at 16:03
  • I tried the `echo $PATH` command, and after observing the results, it doesn't seem to have any "period" in there. `which node` returns `/home/user-name/.nvm/versions/node/v14.17.0/bin/node`. What are the options left with me to fix this? – Rugved Tipare Jun 24 '21 at 16:42
  • Hey, I found a solution to this. Check [this](https://classic.yarnpkg.com/en/docs/install/#debian-stable) page out. Click on `Alternatives` and select `Debian / Ubuntu`. The instructions given in the 'Path Setup' section seemed to work for me! – Rugved Tipare Jun 24 '21 at 17:00
  • 1
    Excellent - Good to hear! Please add that as a self-answer below. Thanks! – NotTheDr01ds Jun 24 '21 at 18:00

0 Answers0