How to Create a React Project
There are many ways to create a React project. In this post, I will introduce the commonly used methods for creating a React project.
Using Vite
To create a react project |
Verify
npm install |
For more details, refer to Scaffolding Your First Vite Project
Using the create-next-app CLI tool
Create a React project with the Next.js framework.
Next.js is an actual framework, or meta-framework as they are also called. You get a bunch of stuff out of the box, like routing and different rendering strategies (SSG, SSR, ISR) access to plug-ins, and so on. If you just need a SPA app you can still use Next but Vite might be easier to get going with, in some case.
# It will run npm install automatically. |
✔ What is your project named? … my-app |
- “Yes” or “No” depends on your needs. Generally, I choose “yes” for all choices.
Verify
npm run dev |
Using the create-react-app CLI tool (Not recommended)
Why create-react-app (CRA) is no longer recommended for use?
- Evolving Ecosystem: Developers now have access to a wide range of tools, libraries, and best practices that may not be compatible with CRA’s default setup.
- Flexibility and Customization: CRA’s simplicity comes at the cost of flexibility. It makes certain assumptions about project structure and build configuration that may not be suitable for every project.
- Performance: CRA’s default Webpack configuration can result in suboptimal build performance, particularly for large applications.
# To create a react project. It will run `npm install` automatically. |
Verify
cd my-app |
For more details, refer to Create React App Documentation
Errors
Error 1: The error Cannot find module 'ajv/dist/compile/codegen'
occurred when run npm start
.
Solutions
npm install ajv --save-dev |
References
[1] The End of an Era: React Team No Longer Recommends Create React App