Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
898 views
in Technique[技术] by (71.8m points)

node.js - 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:UsersDavidpackage.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:UsersDavidAppDataRoaming
pm-cache\_logs2019-12-28T21_32_24_438Z-debug.log```
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:UsersDavid and gave the project name my-app, just type cd my-app (or to be precise type cd C:UsersDavidmy-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+.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...