node.jsreactjsreact-nativeyarn-v2

npx react-native init MyProject: "Error: Command failed: yarn add react-native@latest"


I decided to use Yarn in a new project I wanted to create. I have installed yarn following their instructions.

Yarn v3.3.0

Node v16.13.1

When I hit npx react-native run-android MyProject it throws an error:

> × Downloading template error Error: Command failed: yarn add
> react-native@latest Usage Error: The nearest package directory
> (C:\Users\janic\AppData\Local\Temp\rncli-init-template-eIz0rX) doesn't
> seem to be part of the project declared in C:\Users\janic.
> 
> - If C:\Users\janic isn't intended to be a project, remove any yarn.lock and/or package.json file there.
> - If C:\Users\janic is intended to be a project, it might be that you forgot to list AppData/Local/Temp/rncli-init-template-eIz0rX in its
> workspace configuration.
> - Finally, if C:\Users\janic is fine and you intend AppData/Local/Temp/rncli-init-template-eIz0rX to be treated as a
> completely separate project (not even a workspace), create an empty
> yarn.lock file in it.
> 
> $ yarn add [--json] [-E,--exact] [-T,--tilde] [-C,--caret] [-D,--dev]
> [-P,--peer] [-O,--optional] [--prefer-dev] [-i,--interactive]
> [--cached] [--mode #0] ...

I have already uninstalled the globall @react-native-community/cli and react-native-cli


Solution

  • Updating NodeJs globally to the latest LTS version did the fix.