Template not provided using create-react-app

2020-02-07 14:16发布

When I type the create-react-app my-app command in my terminal, it appears to work - downloading all libraries successfully etc. At the end of that process however I get a message that a template was not provided.

Input

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

Output

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.

In package.json of my-app:

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

I checked out the CRA changelog and it looks like support was added for custom templates - however it doesn't look like the command create-react-app my-app would have changed.

Any idea what is going on here?

29条回答
Emotional °昔
2楼-- · 2020-02-07 14:44

npm uninstall -g create-react-app could be an answer in some cases, but not in mine.

You should manually delete your create-react-app located at ~/.node/bin/ or /usr/bin/ (just type which create-react-app and remove it from locations you saw using rm -rf), next just run npm i -g create-react-app.

After that create-react-app will be working correctly.

查看更多
孤傲高冷的网名
3楼-- · 2020-02-07 14:45

First uninstall create-react-app

npm uninstall -g create-react-app

Then run yarn create react-app my-app or npx create-react-app my-app

then running yarn create react-app my-app or npx create-react-app my-app may still gives the error,

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.

This may happens because of the cashes. So next run

npm cache clean --force 

then run

npm cache verify

Now its all clear. Now run

yarn create react-app my-app or npx create-react-app my-app

Now you will get what you expected!

查看更多
Anthone
4楼-- · 2020-02-07 14:45

I had same problem & i have installed "create-react-app" globally on my machine. There is error :

"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."

Then i removed previous install by using this command.

npm uninstall -g create-react-app

Then install new react app.

npx create-react-app new-app

查看更多
我欲成王,谁敢阻挡
5楼-- · 2020-02-07 14:46

This worked for me.

  1. npm uninstall -g create-react-app
  2. npx create-react-app my-app
查看更多
对你真心纯属浪费
6楼-- · 2020-02-07 14:46

This problem is not solved like this, the problem is in the different instances of node, try removing globally create-react-app and then delete the node_modules and package-lock.json from your root user

查看更多
兄弟一词,经得起流年.
7楼-- · 2020-02-07 14:47

Though already lots of answer is here. I came up with 3 solutions which I applied step by step when I faced this situation.


First step: From Official manual,

If you've previously installed create-react-app globally via npm install -g create-react-app, we recommend you uninstall the package using npm uninstall -g create-react-app to ensure that npx always uses the latest version.

https://create-react-app.dev/docs/getting-started

You can use these commands below:

  • npx create-react-app my-app
  • npm init react-app my-app
  • yarn create react-app my-app

Second step (If first one doesn't work):

Sometimes it may keep caches.then you can use these commands given below.

  • npm uninstall -g create-react-app
  • npm cache clean --force
  • npm cache verify
  • yarn create react-app my-app

Third step:(If these 2 won't work) first uninstall via npm uninstall -g create-react-app,then check if you still have it "installed" with which create-react-app command on your command line. If you got something like (/usr/local/bin/create-react-app) then run this rm -rf /usr/local/bin/create-react-app (folder may vary) to delete manually. Then again install it via npx/npm/yarn.

NB: I succeed in the last step.

查看更多
登录 后发表回答