React Js:没有这样的文件或目录,打开Package.json

问题描述 投票:0回答:3

运行 npm start 时,出现错误 -

PS D:\React\operations_app_tut> npm start

npm ERR! path D:\React\operations_app_tut\package.json
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open 'D:\React\operations_app_tut\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\IT-DI\AppData\Roaming\npm-cache\_logs\2020-12-16T05_56_02_304Z-debug.log

检查物理路径时确保文件存在 -

项目结构供参考 -

我提到了几个网站并再次运行 -npm install 但同样的错误仍然存在。

javascript reactjs npm package.json
3个回答
5
投票

您在错误的文件夹中运行

npm start
。另外为什么外面有package-lock.json。

移动到

D:\React\operations_app_tut\operations_app_tut
目录 然后运行
npm start


1
投票

谢谢@NitinDev 和@Adithya。

如果未来的贡献者面临同样的问题,请添加详细信息 -

我的错误是,我有一个文件夹

D:/React
在这个文件夹中我有我所有的反应项目。 我在
operations_app_tut
 中手动创建了 - 
D:/React

文件夹

此后,我通过路径 :-

D:/React/operations_app_tut
通过 Visual Code 打开它并运行命令 -

npx create-react-app operations_app_tut

此命令在

operations_app_tut
中创建了另一个文件夹,这使得我的项目路径成为 -
D:/React/operations_app_tut/operations_app_tut

由于我在终端上运行 npm start ,路径 -

D:/React/operations_app_tut
这不是实际路径,所以它给了我错误。

课程-

  1. 不要手动创建项目文件夹,它将通过
    npx create-react-app
  2. 自动创建

0
投票

回答您自己对问题的解释。 就我个人而言,我使用了

npx create-next-app@latest
Next),所以我的项目是自动创建的,但我遇到了同样的错误:
npm ERR! enoent Could not read package.json: Error: ENOENT: no such file or directory
如果我理解正确,您需要在 package.json
 文件所在的文件夹 
中运行命令
npm start
(或 npm run dev 与下一个)。

© www.soinside.com 2019 - 2024. All rights reserved.