npm start throwing error 'This is related to npm not being able to find a file.'

Viewed 14129

I just created a react app, it was working fine but once I restart the editor it is throwing error like this :

        Poojas-MacBook-Air:newreact pooja$ npm start
        npm ERR! path /Users/pooja/Desktop/projects/newreact/package.json
        npm ERR! code ENOENT
        npm ERR! errno -2
        npm ERR! syscall open
        npm ERR! enoent ENOENT: no such file or directory, open 
        '/Users/pooja/Desktop/projects/newreact/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!     /Users/pooja/.npm/_logs/2020-11-28T10_27_42_118Z-debug.log

Please help if anyone knows about it.

4 Answers
  1. Make sure you have the latest npm (npm install -g npm).
  2. Add an exception to your antivirus to ignore the node_modules folder in your project.
  3. rm -rf node_modules package-lock.json
  4. npm install

Sometimes the PATH is not correct, just open the cmd and cd to the address where the package.json is and then run npm start

For me, it was because of the running Metro server. If anyone is experiencing this issue in react-native, make sure you have stopped the running Metro server instance before entering npm i <package-name>.
With yarn, I think, there's no such issue.

To resolve package.json file, go to your project folder and find package.json location folder. Open terminal and make sure your are in correct path where package.json file located. eg: c://projectfolder/folder1/clientapp> npm start

enter image description here

Related