简体   繁体   中英

npm start script returns error immediately after installing create-react-app my-first-react-app

As the title states, I just installed the react library and went to start the application for the first time. I'm getting the following error below.

From what I can tell, it seems that the application is looking into the wrong folder to find the starter script. I've not altered any of the initial starter files, or added any of my own. I'm unsure how to address this issue.

npm ERR! errno -4058
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\David\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\David\AppData\Roaming\npm-cache\_logs\2019-12-28T21_32_24_438Z-debug.log```

I think you forgot to cd into (or to change to) your project's directory.

Assuming that you initialised your project in the directory C:\\Users\\David and gave the project name my-app , just type cd my-app (or to be precise type cd C:\\Users\\David\\my-app\\ in your Command Prompt and then run npm start .

The file the error message is complaining about, package.json , is already available inside your project folder.

However, installing create-react-app and then initialising a new app is not the new recommended way.

According to the React documentation , uninstall the create-react-app global npm package and follow the following steps to create a new React app:

npx create-react-app my-app
cd my-app
npm start

Note

npx on the first line is not a typo — it's a package runner tool that comes with npm 5.2+.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM