当我在我的终端上输入create-react-app my-app命令时,它似乎工作了-下载所有库成功等。在该过程结束时,我得到一个消息,没有提供模板。

输入

user@users-MacBook-Pro-2 Desktop% create-react-app my-app

输出

Creating a new React app in /Users/user/Desktop/my-app.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
..... nothing out of the ordinary here .....
✨  Done in 27.28s.

A template was not provided. This is likely because you're using an outdated version of create-react-app.
Please note that global installs of create-react-app are no longer supported.

在包中。my-app的Json:

"dependencies": {
  "react": "^16.12.0",
  "react-dom": "^16.12.0",
  "react-scripts": "3.3.0" <-- up-to-date
}

我检查了CRA更改日志,它看起来像是增加了对自定义模板的支持-但是它看起来不像命令create-react-app my-app会改变。

知道这是怎么回事吗?


当前回答

如果以上这些对你都不起作用,下面就是我所做的: 在ubuntu(可能还有mac和windows)上搜索node_modules文件夹,手动删除create-react-app模块,更新包。Json和包锁。Json,然后再次运行

npx create-react-app <app-name>

作品!

其他回答

如果你之前已经通过npm install -g create-react-app全局安装了create-react-app,我们建议你使用npm uninstall -g create-react-app卸载这个包,以确保npx总是使用最新的版本。

Docs

使用以下命令中的任意一个:

create-react-app my-app NPM init react-app my-app Yarn创建my-app

如果NPM uninstall -g create-react-app上面说的不起作用。 输入create-react-app来知道它被安装在哪里。我的安装在/usr/bin文件夹中。然后执行sudo rm -rf /usr/bin/create-react-app。(感谢下面@v42的评论)

对于Linux,这对我来说是有效的

sudo npm uninstall -g create-react-app
npx create-react-app my-test-app

对于任何Windows用户仍然有这个问题,这是为我解决它:

运行create-react-app获取路径(我的路径是C:\Users\username\AppData\Local\Yarn\bin)。 导航到该目录并删除“create-react-app”和“create-react-app.cmd”。 导航到要在其中启动项目的目录。 运行npm install create-react-app, NPX create-react-app name-of-app, CD name-of-app, yarn start。

步骤4将根据您的配置而有所不同,但这只是我启动和运行的基础。

尝试以管理员身份运行您的终端。我也有同样的问题,除了以管理员身份打开终端,然后执行npx create-react-app yourAppName之外,没有任何帮助

这份工作是给我的:

让我们用下面的命令全局卸载create-react-app:

npm uninstall -g create-react-app

之后在你的项目目录:

npm install create-react-app@latest

最后:

npx create-react-app my-app

对于typescript:

npx create-react-app my-app --template typescript