[英]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.正如标题所述,我刚刚安装了 react 库并第一次启动了应用程序。 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.我认为您忘记cd
进入(或更改到)您的项目目录。
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
.假设您在目录C:\\Users\\David
初始化了您的项目,并将项目名称命名为my-app
,只需键入cd my-app
(或者更准确地说,在您的目录中键入cd C:\\Users\\David\\my-app\\
命令提示符,然后运行npm start
。
The file the error message is complaining about, package.json
, is already available inside your project folder.错误消息所抱怨的文件package.json
已在您的项目文件夹中可用。
However, installing create-react-app
and then initialising a new app is not the new recommended way.然而,安装create-react-app
然后初始化一个新的应用程序并不是推荐的新方法。
According to the React documentation , uninstall the create-react-app
global npm package and follow the following steps to create a new React app:根据React 文档,卸载create-react-app
全局 npm 包,然后按照以下步骤创建新的 React 应用程序:
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+.npx
第一行是不是一个错字-这是一个包亚军工具自带的NPM 5.2+。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.