Search code examples
windowselectronyarnpkgelectron-forge

Yarn throws an error while trying to build electron app


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.


Solution

  • It seems that Yarn assumes it can run the program create-electron-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.