yarn icon indicating copy to clipboard operation
yarn copied to clipboard

cannot run yarn create if yarn is in a folder where the file path has a space

Open liverpoologic opened this issue 6 years ago • 16 comments

Yarn v1.12.3 my laptop (helpfully, thank you windows) installed yarn by default in a directory where the file path includes a space (e.g. C:/Users/Some Name/AppData/Yarn...). This results in the following error when I run yarn create react-app

'C:\Users\Some' is not recognized as an internal or external command,
operable program or batch file.
error Command failed.
Exit code: 1
Command: C:\Users\Some Name\AppData\Local\Yarn\bin\create-react-app
Arguments:
Directory: C:\repos\beaver
Output:

liverpoologic avatar Dec 24 '18 08:12 liverpoologic

Just spent an hour on this very issue until realizing this was the cause - spaces in the profile name.

crossoft avatar Jan 24 '19 22:01 crossoft

If easy, putting quotes around the command would resolve it and still work with non-spaced paths

crossoft avatar Jan 24 '19 22:01 crossoft

It's been a year now, can we get an update on this?

BartArys avatar Dec 07 '19 15:12 BartArys

You need to change the cache to a location without spaces.

yarn config set cache-folder "your path without spaces"

Did work for me!! If this solve your problems, let me know!

lvizrosario avatar Aug 05 '20 21:08 lvizrosario

I also had to change the prefix

yarn config set prefix "your path without spaces"

#6630

chase-meyer avatar Sep 01 '20 10:09 chase-meyer

It is now 2021 and this is still not fixed.

nvm puts node in C:\Program Files\nodejs

yarn create puts the creator in [node directory]\bin

The result of every yarn create whatever is

success Installed "[email protected]" with binaries:
      - create-react-app
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
error Command failed.
Exit code: 1
Command: C:\Program Files\nodejs\bin\create-react-app

npm/npx doesn't have this problem.

q00u avatar Feb 03 '21 00:02 q00u

I have a fix and proposed solution for this! It involves around changing the config, but I hope the devs try to make a workaround around spaced folder by utilizing FolderName~1 style solution.

Solution for the meantime:

First, run these commands yarn cache dir yarn global bin

It'll output something like: C:\Users\Firstname Lastname\AppData\Local\Yarn\Cache\v6 C:\Users\Firstname Lastname\AppData\Local\Yarn\bin

Copy those, and next run this, with slight modification according to your username Firstname: yarn config set cache-folder "C:\Users\Firstname~1\AppData\Local\Yarn\Cache" (without the V6) yarn config set prefix "C:\Users\Firstname~1\AppData\Local\Yarn" (without the bin)

This is not a workaround, this is a fix, and other workarounds that revolves around moving your Yarn configs to a new folder may cause PATH or Environment Variables issue!

Hope this fixes your problem.

ZombieChibiXD avatar Mar 25 '21 11:03 ZombieChibiXD

@ZombieChibiXD's solution did not work for me, but combining their solution with the solution proposed over at https://github.com/vitejs/create-vite-app/issues/23#issuecomment-706492641 for npm did.

Problematic path used as example: C:\Users\Espen Jacobsson

Steps taken:

  • Close any running shell
  • Run cmd in Administrative Mode (mklink is a feature of cmd, and won't work in PowerShell)
  • Create a directory junction (directory hard link) using the mklink command:
    • mklink /J "C:\Users\EspenJacobsson" "C:\Users\Espen Jacobsson"
  • Run commands
    • yarn cache dir
    • yarn global bin

Take note of the output, as stated in the comment above, they will look something like this: C:\Users\Espen Jacobsson\AppData\Local\Yarn\Cache\v6 C:\Users\Espen Jacobsson\AppData\Local\Yarn\bin

  • Run commands:

    • yarn config set cache-folder "C:\Users\EspenJacobsson\AppData\Local\Yarn\Cache" (without the V6)
    • yarn config set prefix "C:\Users\EspenJacobsson\AppData\Local\Yarn" (without the bin)
  • Reload your shell and verify the new paths are set with the yarn cache dir and yarn global bin commands

  • Assuming the paths are correctly changed, yarn create should now hopefully be working

Hope this helps anyone 🙂

espenja avatar Oct 27 '21 22:10 espenja

@ZombieChibiXD's solution looks fancy, but it doesn't work for everyone.

The right way to find the short path should be running dir /x in C:\Users.

image

It's VALORL~1 for me instead of VALOR~1.

ValorLin avatar Apr 17 '22 18:04 ValorLin

I have a fix and proposed solution for this! It involves around changing the config, but I hope the devs try to make a workaround around spaced folder by utilizing FolderName~1 style solution.

Solution for the meantime:

First, run these commands yarn cache dir yarn global bin

It'll output something like: C:\Users\Firstname Lastname\AppData\Local\Yarn\Cache\v6 C:\Users\Firstname Lastname\AppData\Local\Yarn\bin

Copy those, and next run this, with slight modification according to your username Firstname: yarn config set cache-folder "C:\Users\Firstname~1\AppData\Local\Yarn\Cache" (without the V6) yarn config set prefix "C:\Users\Firstname~1\AppData\Local\Yarn" (without the bin)

This is not a workaround, this is a fix, and other workarounds that revolves around moving your Yarn configs to a new folder may cause PATH or Environment Variables issue!

Hope this fixes your problem.

After hours of struggling with this issue, @ZombieChibiXD solution worked for me.

sirpasha avatar Jun 19 '22 23:06 sirpasha

You need to change the cache to a location without spaces.

yarn config set cache-folder "your path without spaces"

Did work for me!! If this solve your problems, let me know!

HOW?

isogunro avatar Jul 08 '22 21:07 isogunro

image

Still a problem in 2022, incredible...

alexandre-le-borgne avatar Jul 19 '22 22:07 alexandre-le-borgne

This is happening to me too .... :( My laptop is a company laptop with was pre--setup by someone else, who wasnt aware of spaces being a problem. Is there any fix for this?

Edit: Just for info, https://github.com/yarnpkg/yarn/issues/6851#issuecomment-953366835 worked for me too.

nikki-cat avatar Aug 23 '22 08:08 nikki-cat

I too am amazed to find this is still a problem in 2022. On Windows we've regularly had spaces in directory names since Windows 95, and on Linux the first ext file system had it since 1992. This should not still be a problem 27/30 years later.

Many of the workarounds above will not work because the Yarn configuration file ".yarnrc" exists in our user home directory which is a very common place for a space to be present at, so any configuration change you make (even with the junction or symbolic link approach) will not persist.

Adambean avatar Oct 09 '22 13:10 Adambean

yarn config set cache-folder "C:\path\without\spaces\.yarn-cache" yarn config set prefix "C:\path\without\spaces\.yarn"

just run these two command and confirm changes using this command yarn config list

Thank me later <3

muhammad-shahin avatar Jan 10 '24 02:01 muhammad-shahin

Run this command in command prompt: yarn config set prefix "\AppData\Local\bin" Screenshot 2024-03-06 213445

U are good to go

Tanujch03 avatar Mar 06 '24 16:03 Tanujch03