Home > OS >  Yarn throws an error while trying to build electron app
Yarn throws an error while trying to build electron app

Time:02-12

When I try to create an electron app via yarn create electron-app "my-app", it throws an error saying

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

What should I do? I'm new to yarn, and npm worked fine. This also only happens on windows, when I use my iMac on Monterey or my linux laptop the command runs fine.

Thanks

CodePudding user response:

Analysis

It seems that yarn assumes it can run the program create-react-app without considering spaces in the file path. Unfortunately, this does not work and only the part up to the first space is considered a program to run, hence you get the error message that C:\Users\Lincoln is not a valid command.

The problem is discussed in this yarn issue. The key idea in the workarounds is to accept yarn's behavior and give it a file path that doesn't contain spaces. There are two concrete ideas:

Option A - Use directory name abbreviation to skip the space
yarn config set cache-folder "C:\Users\Lincol~1\AppData\Local\Yarn\Cache"
yarn config set prefix "C:\Users\Lincol~1\AppData\Local\Yarn"

For this to work, make sure to take 6 characters from the actual directory name and then append ~1. If the space happens to occur within the first 6 characters, this approach will not work for you.

Option B - Make another user folder, skipping the space (using junction)
mklink /J "C:\Users\Lincoln-Muller" "C:\Users\Lincoln Muller"
yarn config set cache-folder "C:\Users\Lincoln-Muller\AppData\Local\Yarn\Cache"
yarn config set prefix "C:\Users\Lincoln-Muller\AppData\Local\Yarn"

A junction allows two directory names to point at the same file system structure. That means that there are two ways to address the same directory. Their contents cannot diverge because they are the same directory.

CodePudding user response:

The issue is that you have a space in your directory name and you haven't correctly escaped it.

C:\Users\Lincoln Muller

This looks like you are trying to pass the parameter Muller to program C:\Users\Lincoln

I suggest just using a folder that doesn't contain spaces or escape the [space character].

https://www.howtogeek.com/694949/how-to-escape-spaces-in-file-paths-on-the-windows-command-line/

Three Ways to Escape Spaces on Windows There are three different ways you can escape file paths on Windows:

By enclosing the path (or parts of it) in double quotation marks ( ” ).

By adding a caret character ( ^ ) before each space. (This only works in Command Prompt/CMD, and it doesn’t seem to work with every command.)

By adding a grave accent character ( ` ) before each space. (This only works in PowerShell, but it always works.)

  • Related