npx react-native init MyProject:“错误:命令失败:纱线添加react-native@latest”

问题描述 投票:0回答:2

我决定在我想要创建的新项目中使用 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

node.js reactjs react-native yarn-v2
2个回答
0
投票

将 NodeJs 全局更新到最新的 LTS 版本即可修复。


0
投票

更新纱线是我的解决办法。

npm i -g yarn
© www.soinside.com 2019 - 2024. All rights reserved.