当我在我的终端上输入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会改变。

知道这是怎么回事吗?


当前回答

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

其他回答

对于UBUNTU:如果你有一个错误的模板没有提供npx create-react-app,并且已经卸载了npm create-react-app -g,仍然不能工作,请执行以下操作:

sudo rm -rf usr/bin/create-react-app    

# this will manualy remove the create-react-app. 
npx create-react-app 

使用typescript也可以。

我也遇到了同样的问题,我已经在我的机器上全局安装了“创建-反应-应用程序”。 有错误:

“没有提供模板。这可能是因为您使用的是过时版本的create-react-app。 请注意,不再支持create-react-app的全球安装。”

然后我删除了以前的安装使用这个命令。

NPM卸载-g create-react-app

然后安装新的react应用程序。

create-react-app new-app

在你的电脑上安装-g create-react-app 用NPX Create -react-app my-app再次创建react项目

最简单的方法之一就是使用

npx --ignore-existing create-react-app [project name]

这将删除create-react-app的旧缓存版本,然后获取新版本来创建项目。

注意:添加项目名称很重要,因为忽略现有的create-react-app版本是过时的,并且机器全局环境中的更改是临时的,因此以后仅使用npx create-react-app[项目名称]将无法提供所需的结果。

NPX create-react-app@latest your-project-name

在尝试了所有的答案后为我工作,希望能在未来帮助到别人。