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条回答
地球回转人心会变
2楼-- · 2020-02-07 14:47

For Windows 10 I had to manually delete some folders in yarn's cache, my path was something like C:\Users\username\AppData\Local\Yarn\Cache\v1 and the foldes I had to remove were something like npm-create-react-app-1.0.0-1234567890abcdef

查看更多
Luminary・发光体
3楼-- · 2020-02-07 14:48

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

This is reported at https://create-react-app.dev/docs/getting-started/. For me, this did not work. I had to re-install create-react-app globally instead.

My steps to fix this problem were to:

  1. npm uninstall -g create-react-app
  2. npm install -g create-react-app
  3. npx create-react-app my-app
查看更多
够拽才男人
4楼-- · 2020-02-07 14:48

Such a weird problem because this worked for me yesterday and I came across the same error this morning. Based on the release notes, a new feature was added to support templates so it looks like a few parts have changed in the command line (for example, the --typescript was deprecated in favor of using --template typescript)

I did manage to get it all working by doing the following:

  1. Uninstall global create-react-app npm uninstall create-react-app -g.
  2. Verify npm cache npm cache verify.
  3. Close terminal. I use the mac terminal, if using an IDE maybe close and re-open.
  4. Re-open terminal, browse to where you want your project and run create-react-app via npx using the new template command conventions. For getting it to work, I used the typescript my-app from the documentation site to ensure consistency: npx create-react-app my-app --template typescript

If it works, you should see multiple installs: one for react-scripts and one for the template. The error message should also no longer appear.

查看更多
狗以群分
5楼-- · 2020-02-07 14:49

This work's for me :

Let's, uninstall create-react-app globally by this command:

npm uninstall -g create-react-app

After that in your project directory:

npm install create-react-app@latest

At the last:

npx create-react-app my-app

For typescript :

npx create-react-app my-app --template typescript
查看更多
We Are One
6楼-- · 2020-02-07 14:51

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.

Docs

Use either one of the below commands:

  • npx create-react-app my-app
  • npm init react-app my-app
  • yarn create react-app my-app
查看更多
登录 后发表回答