我决定在我想要创建的新项目中使用 Yarn。我已经按照他们的说明安装了纱线。
纱线 v3.3.0
节点 v16.13.1
当我点击
npx react-native run-android MyProject
时,它会抛出错误:
> × 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] ...
我已经卸载了全局
@react-native-community/cli
和 react-native-cli
将 NodeJs 全局更新到最新的 LTS 版本即可修复。
更新纱线是我的解决办法。
npm i -g yarn