运行 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 但同样的错误仍然存在。
您在错误的文件夹中运行
npm start
。另外为什么外面有package-lock.json。
移动到
D:\React\operations_app_tut\operations_app_tut
目录
然后运行npm start
谢谢@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
这不是实际路径,所以它给了我错误。
课程-
npx create-react-app
回答您自己对问题的解释。 就我个人而言,我使用了
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
与下一个)。