删除旧版本的 create-react-app

Yon*_*Nir 4 npm reactjs create-react-app npx

我想使用该脚本创建一个新的反应应用程序create-react-app。我仍然安装了一个不再受支持的全局版本,因此我卸载了全局版本并尝试创建一个新版本,如下所示:

npx create-react-app myapp
Run Code Online (Sandbox Code Playgroud)

然后我收到一个错误,提示没有使用模板,并且我可能使用旧版本的 create-react-app。我在网上阅读,这确实有效:

npx --ignore-existing create-react-app myapp
Run Code Online (Sandbox Code Playgroud)

我读到这意味着即使我确实卸载了全局版本,我仍然拥有旧版本。那么如何删除其他旧版本的 create-react-app 呢?

Ape*_*pex 7

以下步骤解决了删除旧版本并创建 create-react-app 的问题。

1 使用 . 检查 create-react-app 的版本npx create-react-app -V

2 使用 或 卸载任何全局版本的 create-react- npm uninstall -g create-react-appapp yarn global remove create-react-app

3 查看你机器_npx文件夹的内容,里面的每个文件夹代表安装的一个node版本。使用ls -a /Users/<username>/.npm/_npx/

4 在package.json文件中查看步骤3中找到的node版本中create-react-app的版本。例子nano /Users/<username>/.npm/_npx/c67e74de0542c87c/package.json

5 删除节点版本文件夹。例子rm -rf /Users/<username>/.npm/_npx/c67e74de0542c87c。当您运行步骤 6 时,它将重新创建。或者,您可以重命名该文件夹以确保安全。

6 创建反应应用程序。npx create-react-app my-app。您应该会看到继续创建应用程序的提示。