npm start errors with ERR! code ENOENT, syscall open
Asked Answered
F

17

32

I'm suddenly 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 [email protected]
3 info using [email protected]
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"
    ]
  }
}

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

Fluky answered 20/2, 2020 at 11:46 Comment(2)
The error is pretty self-explanatory. There is no package.json file in the folder you are npm installing from.Delocalize
Ensure you are installing in the root folder where the package.json is located.Actium
P
12

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.

Philanthropic answered 20/2, 2020 at 12:0 Comment(0)
C
7

There can be one or more reason, but following solution could help you.

If you initialize npm install without having

package.json

file then, it will give you such error. Because npm needs some information which is stored in package.json file.

For this you can write

npm init -y

This will create a new package.json file and now you can write npm.

Cypro answered 27/8, 2022 at 12:32 Comment(0)
D
2

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

Deft answered 11/3, 2021 at 8:47 Comment(0)
N
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

Nesto answered 28/1, 2021 at 11:5 Comment(1)
I had the same problem and also did the same thing using the solution in github but still didn't work for me. Are you also using vagrant and virtualbox?Cerell
G
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.

Gaffe answered 28/4, 2021 at 4:41 Comment(0)
B
0

I had this same exact issue, but if you go back an reinstall it, you’ll see that the instructions say to make sure that your user path is localized. Once I switched my path to localized and entered npm i into the terminal, it installed no problem.

Borgeson answered 22/1, 2022 at 4:27 Comment(0)
T
0
  1. Check if there is package.json file or not if not then run npm init and fill the details.

  2. I got this error while installing nodemon package and when I created index.js file or any js file it didn't throw me error.

  3. You can cd to the root folder and then once again cd to the app directory where the package.json is there.

Tetanus answered 22/2, 2022 at 7:45 Comment(0)
S
0

Solved it!

Just open another cli (CMD, Git bash, node cli) and go to the desired react app folder and run

-npm start

I am assuming you are using vs code with dual server (port) backend and react

Solicit answered 10/2, 2023 at 21:13 Comment(0)
L
0

I was also getting the same error as you guys but...

npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path F:\6 sem Project\olx/package.json
npm ERR! errno -4058
npm ERR! enoent
ENOENT: no such file or directory, open 'F:\6 sem Project\olx\package.json'

My solution I deleted my node modules folder and package.json file then tryed to run npm install but couldn't do it So I basically installed node module folder outside my main folder (i.e when you create npx create-react-app myapp) outside main folder run npm intall ,["myapp" refers to main folder here] then I drag-down my node module and package.json folder to "myapp" and then run npm start and at this moment it finally worked for me.

Louque answered 26/4, 2023 at 20:6 Comment(0)
M
0

enter image description here

I had same issue on my office system. It was happening because the path where it was created need admin permission so couldn't able to create package.json.

I suggest to create project in a different drive where crud operation doesn't requires admin permission or any credential.

Maracanda answered 5/9, 2023 at 14:41 Comment(0)
A
0

That has might be a problem with cache. Run npm cache clean --force wait for the clean process to end then try installing your dependency again.

Example Run:

npm cache clean --force

Then:

npm i axios
Audrey answered 2/2 at 21:10 Comment(0)
H
0

Create the Missing Directory You can manually create the missing directory to resolve this issue.

  1. Open File Explorer.
  2. Navigate to C:\Users\user_name\AppData\Roaming.
  3. Create a new folder named npm.

Clear npm Cache

  1. Open your terminal.

  2. Run the following command: npm cache clean --force Reinstall npm

  3. Open terminal

  4. Run this command : npm install -g npm

Now you can run npm start and it should work.

Hydrate answered 29/5 at 15:5 Comment(0)
F
-1

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

Francophile answered 25/4, 2021 at 10:0 Comment(0)
O
-1

Also you can check package.json in your project folder. If package.json doesn't exist try to create this or rename package-lock.json. After that: npm install in your project folder and npm run if you use latest version. It works to me.

Ortego answered 12/1, 2022 at 11:1 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Slovenia
C
-1

Please check whether you opened the correct folder.

You should navigate to the project before running the application (i.e., before executing npm start).

When you create a new project, you should execute cd {project_Name} before executing the npm start command.

If the problem remains, the issue is at the node package installation. Please install the node packages (npm i) to solve this issue.

Caco answered 1/4, 2023 at 8:43 Comment(0)
S
-2

you need to start by initializing npm by using

npm init

after that install npm by using

npm install

Stereopticon answered 8/6, 2021 at 17:25 Comment(0)
I
-3

I just install the visual studio code and this problem was solved

Impassioned answered 24/9, 2021 at 18:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.