twuni / asdf-yarn

asdf plugin for Yarn.
MIT License
139 stars 25 forks source link

Yarn Installation Issues in WSL 2 #15

Closed firrae closed 3 years ago

firrae commented 3 years ago

Hi there, this might not be specific to WSL 2, but it seems when I try to run asdf install yarn 1.22.5 (or latest) but I always get the following result:

steve@DESKTOP-FAEGT4O:/mnt/c/Users/X/Projects/closet/closet-web$ asdf install yarn 1.22.5
/home/steve/.asdf/plugins/yarn/bin/install: line 2: $'\r': command not found
: invalid option namegins/yarn/bin/install: line 3: set: errexit
/home/steve/.asdf/plugins/yarn/bin/install: line 5: $'\r': command not found
/home/steve/.asdf/plugins/yarn/bin/install: line 6: syntax error near unexpected token `$'{\r''
'home/steve/.asdf/plugins/yarn/bin/install: line 6: `asdf_yarn_fail() {

Any thoughts on what I'm missing, or is this another issue? I'm running bash inside:

Distributor ID: Ubuntu
Description:    Ubuntu 20.04.1 LTS
Release:        20.04
Codename:       focal
canterberry commented 3 years ago

Based on the output, it looks like a newline processing issue -- something transformed \n into \r\n, which is causing bash to interpret the \r as a command. A number of things could have potentially caused an implicit newline transformation like that (most likely git configuration or UI or an IDE, or something odd about that variant of bash).

It's a shot in the dark, but I see you're invoking the command from within a Windows filesystem (/mnt/c/Users/...). That could be triggering some WSL magic, even though the asdf install script itself is mounted in a Linux filesystem. Maybe try running the install command from /home/steve instead.

Barring that, you can strip out the superfluous \rs with a quick sed -i'' -E 's|\r||g' /home/steve/.asdf/plugins/yarn/bin/install (or your choice of any number of other methods, of course).

I'm curious what the root cause of the issue is, and whether it's anything the install script could take into account. Since the symptom is that the install script itself isn't readable, it seems unlikely a resolution would be entirely within the domain of the plugin. At least some documentation might come out of it, though, to help others who might encounter the same.

firrae commented 3 years ago

Hm, interesting thought @canterberry, I'll try it out tonight and see what happens on the Linux filesystem.

canterberry commented 3 years ago

Hi @firrae , did you ever get a chance to try this out from the Linux filesystem? I'll also see if I can repro on my WSL environment.

firrae commented 3 years ago

@canterberry I have not sorry. life has been extremely busy recently. I will try to test it this weekend though as things begin to slow down a bit.

firrae commented 3 years ago

@canterberry Same error:

steve@DESKTOP-FAEGT4O:~$ asdf install yarn 1.22.5
/home/steve/.asdf/plugins/yarn/bin/install: line 2: $'\r': command not found
: invalid option namegins/yarn/bin/install: line 3: set: errexit
/home/steve/.asdf/plugins/yarn/bin/install: line 5: $'\r': command not found
/home/steve/.asdf/plugins/yarn/bin/install: line 6: syntax error near unexpected token `$'{\r''
'home/steve/.asdf/plugins/yarn/bin/install: line 6: `asdf_yarn_fail() {

Sorry for the delay in this, it's been crazy for me.

canterberry commented 3 years ago

No worries, @firrae. Life happens!

I'm not quite sure what is going on, but it almost certainly has to do with some part of the toolchain adding \r characters where they shouldn't be, and/or a bash executable that does not sanely handle those characters. Either way, it wouldn't be something within asdf-yarn's jurisdiction, but nonetheless a relevant problem for this community to try and solve.

I've exhausted my immediate ideas, and invite others who may have more WSL 2 expertise to chime in case maybe this is a common or known issue with workarounds.

canterberry commented 3 years ago

Closing due to inactivity.