当我在我的终端上输入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会改变。
知道这是怎么回事吗?
先清空你的npm缓存,然后使用yarn,如下所示:
NPM缓存清理——force
NPM缓存验证
Yarn创建my-app
我希望这能有所帮助。
EDIT
...在我进一步研究了这个问题之后,你可能想尝试以下方法:
NPM卸载-g create-react-app
Yarn全局删除create-react-app
which create-react-app -如果它返回一些东西(例如/usr/local/bin/create-react-app),然后执行rm -rf /usr/local/bin/create-react-app手动删除。
NPM缓存清理——force
NPM缓存验证
npx create-react-app@latest
These steps should remove globally installed create-react-app installs, you then manually remove the old directories linked to the old globally installed create-react-app scripts. It's then a good idea to clear your npm cache to ensure your not using any old cached versions of create-react-app. Lastly create a new reactjs app with the @latest option like so: npx create-react-app@latest. There has been much confusion on this issue where no template is created when using npx create-react-app, if you follow the steps I have stated above (1-6) then I hope you'll have success.
p.s.
如果我想在一个叫client的目录中创建一个react应用程序,那么我会在终端中输入以下命令:
NPX create-react-app@latest ./client
祝你好运。
1)
npm uninstall -g create-react-app
or
yarn global remove create-react-app
2)
似乎有一个错误,create-react-app没有正确卸载,使用其中一个新命令导致:
没有提供模板。这可能是因为您正在使用
过时版本的创建-反应-应用程序。
在使用npm uninstall -g create-react-app卸载后,检查你的命令行上是否仍然“安装”了create-react-app (Windows: where create-react-app)。如果它返回一些东西(例如/usr/local/bin/create-react-app),然后执行rm -rf /usr/local/bin/create-react-app手动删除。
3)
下面是其中一种方法:
npx create-react-app my-app
npm init react-app my-app
yarn create react-app my-app
首先卸载create-react-app
npm uninstall -g create-react-app
然后运行yarn create react-app my-app或npx create-react-app my-app
然后运行yarn create react-app my-app或NPX create-react-app my-app可能仍然会给出错误,
没有提供模板。这可能是因为您使用的是过时版本的create-react-app。请注意,不再支持create-react-app的全局安装。
这可能是因为现金的原因。所以下一组
npm cache clean --force
然后运行
npm cache verify
现在一切都清楚了。现在运行
Yarn create react-app my-app或NPX create-react-app my-app
现在你会得到你想要的!
把以上的答案加起来:
随着新版本的create-react-app,您可以使用自定义模板创建一个新的应用程序。
目前有两个模板可用:
cra-template
cra-template-typescript
用法:
npx create-react-app my-app [--template typescript]
更多关于create-react-app的最新变化:
https://github.com/facebook/create-react-app/releases/tag/v3.3.0