0

This is a followup question to my earlier question (but is an independent question)

I am trying to install react and react-dom on a Mac:

npm install --save react react-dom

but get the following warnings (path names replaced with ...):

npm WARN saveError ENOENT: no such file or directory, open '/Users/../Z/package.json'
/Users/.../Z
├─┬ [email protected] 
│ ├─┬ [email protected] 
│ │ ├── [email protected] 
│ │ ├─┬ [email protected] 
│ │ │ ├─┬ [email protected] 
│ │ │ │ ├─┬ [email protected] 
│ │ │ │ │ └── [email protected] 
│ │ │ │ └── [email protected] 
│ │ │ └── [email protected] 
│ │ ├─┬ [email protected] 
│ │ │ └── [email protected] 
│ │ ├── [email protected] 
│ │ └── [email protected] 
│ ├─┬ [email protected] 
│ │ └── [email protected] 
│ └── [email protected] 
└── [email protected] 

npm WARN enoent ENOENT: no such file or directory, open '/Users/.../Z/package.json'
npm WARN Z No description
npm WARN Z No repository field.
npm WARN Z No README data
npm WARN Z No license field.

I searched around a bit but did not find a good reason for these warnings. SO posts like these seem to suggest installing react in the same directory where node modules are installed. My node is installed in usr/local/bin but package.json does not appear anywhere on the machine even on a global search. I just installed npm before trying to install react so don't think its a versioning issue.

2
  • Is your terminal currently set to the root directory of your project, where package.json is? What do you get when you run pwd (print working directory) and ls (list)? Feel free to edit your question with this information. Commented Dec 27, 2016 at 7:32
  • I am in the root directory of the project but as I mentioned, I dont have package.json anywhere on my machine Commented Dec 27, 2016 at 7:39

3 Answers 3

6

If this is a brand new project, it can be resolved by running npm init from the root directory of your project (where you want package.json to be created), and press "ENTER" at all of the prompts to accept the default answers. (It is easy to change your responses by directly modifying the package.json file later.)

Once the package.json has been created, you will be able to run npm install commands!

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks, that did it for me. I wonder why this important piece of information (of running 'npm init') does not appear in react installation documentation (facebook.github.io/react/docs/installation.html).
@AnupamJain It's one of those first-step things that doesn't get mentioned bc you're somewhat expected to know it. But now that you know, and you'll never forget! :) (This, too, is how I learned that npm init and package.json are mandatory.)
Thanks, I have been trying to mark it as accepted answer but SO wants me to wait for 5 minutes :) Looks like the init bit is more about npm than react which is probably why it does not appear in the react documentation but good to know for newbies (to both React and Node) like me.
Update: Now updated the React doc to include npm init (github.com/facebook/react/pull/8649). Should be visible after the commit gets pushed.
npm init does fix the problem and creates package.json.However, in my case, react already had a package.json (which was not detected by npm audit fix). As a result, second package.json file will be created.
2

Actually for me it just worked like this : I ran npx create-react-app "nameOfProject" , if you type npm start in the same folder it won't work because it tries to find the package.json in the same folder , when your package.json is in the subfolder ( the folder of the "nameOfProject" ). Run cd "nameOfProject" to change the directory and them run npm start .

1 Comment

If you run npm init or npm install again it will just install another package,json there and it will be a mess
0

Check the folder you're in. Usually after using npx create-react-app, you'll be in the same folder. you will be needed to cd into the new folder that is created after running above command. there you'll find package.json.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.