问题描述
正如标题所说,我刚刚安装了反应库并第一次启动了应用程序.我在下面收到以下错误.
据我所知,该应用程序似乎在查找错误的文件夹以查找启动脚本.我没有更改任何初始启动文件,也没有添加我自己的任何文件.我不确定如何解决这个问题.
npm 错误!错误号 -4058npm 错误!系统调用打开npm 错误!enoent ENOENT: 没有那个文件或目录,打开'C:\Users\David\package.json'npm 错误!enoent 这与 npm 无法找到文件有关.npm 错误!恩恩特npm 错误!可以在以下位置找到此运行的完整日志:npm 错误!C:\Users\David\AppData\Roaming\npm-cache\_logs\2019-12-28T21_32_24_438Z-debug.log```
我想你忘记了 cd
进入(或更改到)你的项目目录.
假设您在目录 C:\Users\David
中初始化了您的项目并指定了项目名称 my-app
,只需键入 cd my-app
(或者更准确地说,在命令提示符中键入 cd C:\Users\David\my-app\
,然后运行 npm start
.
错误消息所抱怨的文件 package.json
已在您的项目文件夹中可用.
但是,安装 create-react-app
然后初始化一个新应用并不是推荐的新方法.
根据 React 文档,卸载 create-react-app
全局 npm 包并按照以下步骤创建一个新的 React 应用程序:
npx create-react-app my-appcd 我的应用程序启动
注意
第一行的npx
不是打字错误——它是一个包运行工具带有 npm 5.2+.
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
这篇关于npm start 脚本在安装 create-react-app my-first-react-app 后立即返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!