8

I'm suddently having a problem with "npm start" in my React application. When I trigger it, this is what I receive:

npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /mnt/c/Users/pal/Desktop/dev/myApp/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/mnt/c/Users/pal/Desktop/dev/myApp/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!     /home/palnic/.npm/_logs/2020-02-20T11_30_39_463Z-debug.log

This is the debug.log:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'start' ]
2 info using npm@6.13.7
3 info using node@v12.13.1
4 verbose stack Error: ENOENT: no such file or directory, open '/mnt/c/Users/pal/Desktop/dev/myApp/package.json'
5 verbose cwd /mnt/c/Users/pal/Desktop/dev/myApp/package.json
6 verbose Linux 4.4.0-18362-Microsoft
7 verbose argv "/usr/bin/node" "/usr/bin/npm" "start"
8 verbose node v12.13.1
9 verbose npm  v6.13.7
10 error code ENOENT
11 error syscall open
12 error path /mnt/c/Users/pal/Desktop/dev/myApp/package.json
13 error errno -2
14 error enoent ENOENT: no such file or directory, open '/mnt/c/Users/pal/Desktop/dev/myApp/package.json'
15 error enoent This is related to npm not being able to find a file.
16 verbose exit [ -2, true ]

I tried the following solution:

sudo npm install -g npm     //(ok!)
sudo npm cache clean   //(not working if not using --force flag)

And then npm install returns:

npm WARN saveError ENOENT: no such file or directory, open '/mnt/c/Users/pal/Desktop/dev/myApp/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/mnt/c/Users/pal/Desktop/dev/myApp/package.json'
npm WARN myApp No description
npm WARN myApp No repository field.
npm WARN myApp No README data
npm WARN myApp No license field.

up to date in 0.454s
found 0 vulnerabilities

My npm version is: 6.13.7

This is my package.json

{
  "name": "myApp",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.4.0",
    "@testing-library/user-event": "^7.2.1",
    "firebase": "^7.7.0",
    "node-sass": "^4.13.1",
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-redux": "^7.1.3",
    "react-router-dom": "^5.1.2",
    "react-scripts": "3.3.0",
    "react-stripe-checkout": "^2.6.3",
    "redux": "^4.0.5",
    "redux-logger": "^3.0.6",
    "redux-persist": "^6.0.0",
    "redux-saga": "^1.1.3",
    "redux-thunk": "^2.3.0",
    "reselect": "^4.0.0",
    "styled-components": "^5.0.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

ADo you have any ideas on the possible causes and the possible solutions?

palnic
  • 132
  • 1
  • 1
  • 9

11 Answers11

16

Just CD to the app directory where package.json is and run npm start again.

Marvelous Ikechi
  • 1,070
  • 1
  • 11
  • 18
5

I think you forgot to open a terminal inside the project folder problem which i faced

so solution is change directory to your path where your package.json file is solution

My project folder is Currency not CurrancyConverter

cd currency 

this is best solution which i found !!!

Anuj
  • 41
  • 1
  • 6
2

Your stated error:

npm WARN saveError ENOENT: no such file or directory, open '/mnt/c/Users/pal/Desktop/dev/myApp/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/mnt/c/Users/pal/Desktop/dev/myApp/package.json'
npm WARN myApp No description
npm WARN myApp No repository field.
npm WARN myApp No README data
npm WARN myApp No license field.

You can check the bold lines. It explains that you are not in the directory which contains the package.json file.

Most of the times you should run this command in the app directory. So, you need to cd into the directory which holds package.json then there you can run your commands like npm install, npm start etc.

So, before running these commands please check if you are in the correct directory.

Jai
  • 71,335
  • 12
  • 70
  • 93
1

Use cd to the home directory of your project (or a directory where package.json is located) and then run the npm start command.

This usually happens while working with terminals.

xKobalt
  • 1,478
  • 2
  • 11
  • 19
1

This is because you have done

npm install 

and

npm start

from outside the project directory to overcome this issue. first do

cd project-name

then do

npm install
npm start

I hope this will solve your issue because it works for me.

Aravind
  • 165
  • 1
  • 9
0

You need to cd (Change directory) into the proper directory where your package.json is.

0

This is error is only come when we outside the project and try to npm start just make sure you are in the correct folder double-check where package.json file is there. In my case, I have new app folder in which my-app folder is there so I was confused and thought I am in the correct folder. so Please make sure you are in the right folder where you are going to enter npm start

I hope it ll work.

Sonali
  • 99
  • 1
  • 3
0

If you are in the right directory and your project is in a shared folder in virtual box and your error shows up due to a missing package.json file in one of the modules folder like below, then it has nothing to do with npm or package-lock, and something to do with virtual box shared folders.

Here is my error.

npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path <project_location>/node_modules/yargs/node_modules/string-width/package.json.3307748328
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '<project_location>/node_modules/yargs/node_modules/string-width/package.json.3307748328'

I found that this is a well known issue here with a lot of good suggestions on how to fix it.

https://github.com/npm/npm/issues/992

I ended up using this one:

https://github.com/npm/npm/issues/992#issuecomment-289935776

Mubashar Abbas
  • 4,346
  • 2
  • 32
  • 42
0

If you are trying npm start in correct directory and it doesn't worked yet, I was same issue. My directory was (...)/web/ web so I changed the local of my project to (...)different_name_subdirectory/web and it worked for me

0

You probably are in one external file. You have to start the project in the inner file of the project. pay attention to the command line. like this error : C:\projects\file A\file B...\fileX solve:C:\projects\file A\file B...\fileX\reactFile

0

I get the same error but not the directory problem.

In my case, I put Wrong Environment Variable declare in .env file.

So, if you face the exact same problem but not directory problem, please check your .env (environment variable) of your project.

Zin Minn
  • 701
  • 2
  • 8
  • 22