【发布时间】:2022-01-17 23:29:33
【问题描述】:
我遇到了涉及全局安装的 npx create-react-app 问题。我的困惑是因为据我所知我的机器上没有安装 create-react-app 包。
一些细节:
我开始了一个 react 项目(使用 typescript 模板),就像我之前和最近在同一台机器上所做的一样:
npx create-react-app --template typescript .
我从终端得到这个提示
Need to install the following packages: create-react-app Ok to proceed? (y)
我按 y 确认可以继续。 (如果我按 n,进程将终止并出现以下错误:npm ERR! canceled。)然后终端显示以下消息
You are running `create-react-app` 4.0.3, which is behind the latest release (5.0.0).
We no longer support global installation of Create React App.
Please remove any global installs with one of the following commands:
- npm uninstall -g create-react-app
- yarn global remove create-react-app
The latest instructions for creating a new app can be found here:
https://create-react-app.dev/docs/getting-started/
我运行两个建议的命令来全局卸载 create-react-app。 npm 顺利:
npm uninstall -g create-react-app
up to date, audited 1 package in 179ms
found 0 vulnerabilities
全局纱线卸载结果显示以下消息:
remove create-react-app
yarn global v1.22.17
warning package.json: No license field
[1/2] ???? Removing module create-react-app...
error This module isn't specified in a package.json file.
info Visit https://yarnpkg.com/en/docs/cli/global for documentation about this command.
最后我尝试查找我的机器上是否存在 create-react-app
which create-react-app
这导致
create-react-app not found.
我不确定如何解决这个问题。
编辑:Deepthi 和 Sators 提供的解决方案。我必须使用命令清除存储旧版本 create-react-app 的 npx 缓存:
npx clear-npx-cache
【问题讨论】:
标签: reactjs typescript yarnpkg npx