Reputation: 191
npm install -g create-react-app, Why it is mandatory to write before creating any react project. If I globally install npm then why it is required to install npm another time for another folder or project.
It always shows the below error:-
npm ERR! enoent ENOENT: no such file or directory, open 'E:\AvatarDemo\AvatarDemoAwesome\package.json' npm ERR! enoent This is related to npm not being able to find a file. npm ERR! enoent
npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\NAFFY KAUSAR\AppData\Roaming\npm-cache_logs\2020-06-23T15_12_49_522Z-debug.log PS E:\AvatarDemo\AvatarDemoAwesome> npm install -g create-react-app C:\Users\NAFFY KAUSAR\AppData\Roaming\npm\create-react-app -> C:\Users\NAFFY KAUSAR\AppData\Roaming\npm\node_modules\create-react-app\index.js
Upvotes: 5
Views: 24992
Reputation: 1172
I was experiencing a similar error and terminal (foolishly, on my part) was is a parent directory instead of the correct one (where package.json
was correctly located).
All I did in terminal was cd [insert correct directory name here, overwriting brackets]
and that corrected the problem.
Upvotes: 0
Reputation: 5581
It is not mandatory to use create-react-app
when making a React project. It's handy to use it because it initializes the project for you and might save you some work though. For a node
project you need a package.json
file and this will create one for you if you run it along with some default dependencies needed by React.
Note that the command you talk about (npm install -g create-react-app) just asks npm
to install the create-react-app
module globally on your computer. It does not run the tool for you. You can run it with the command npx create-react-app my-app
which will create a folder called my-app
with a package.json
and other files in it. It's just a convenience though. You can do all of this file setup yourself if you want to.
The error you're getting is from trying to run npm start
(or a similar command) in a folder that does not have a package.json
file yet. A package.json
file is mandatory for npm
and node
to know what to do.
So the mandatory action is to create a package.json
file. The create-react-app
utility is just a handy way to do that if you are making a React app.
Upvotes: 0
Reputation: 1084
Maybe a different way of looking at this the create react package is a website sample site builder. The create react package generates a skeleton app for you with everything you need to build a react app. To build a sample website you need to use the package and pass in a name:
npm install -g create-react-app
The above command installs the builder
npx create-react-app CustomName
Generates a website from the builder
Upvotes: 10