npm start errors with ERR! code ENOENT, syscall open - node.js

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?

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

I think
you forgot to open a terminal inside the project folder
so solution is change directory to your path where your package.json file is
My project folder is Currency not CurrancyConverter
cd currency
this is best solution which i found !!!

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.

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.

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.

This is because you are running command outside of project.
cd project_name
npm install

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

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.

it is very small problem
you can easily overcome this problem by changing the directory of the folder
you can
see here that I made a mistake in the directory because I am trying to run npm in to the react-proj but I already made a folder called quiz-app so I changed the directory by writing cd {folder name} like cd quiz-app
then run the file
npm start
I hope it will solve your problem

After successful installation, navigate to the cd project-name and then do
npm start

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

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

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

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.

Might be you are not starting your React app from source folder.
Error: npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path D:\rn-starter/package.json
you need to check where is your source code is located.

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.

Check if there is package.json file or not if not then run npm init and fill the details.
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.
You can cd to the root folder and then once again cd to the app directory where the package.json is there.

start the npm in your folder where you create react app.
example:
enter image description here

the same issue occur on my project terminal when i am install npm start because my project path was not correct then i am cd command and go to in coorect path of path then my issue was solve

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.

Encountered the same error.
Root Cause:
Not installing(npm i) and starting(npm start) from the correct path
in terminal
Solution:
Change the directory to the application directory where package.json
present
hope this might help, Thanks.

just cd to the folder which you have created which has the project files. Then run npm start.

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

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

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.

you need to start by initializing npm by using
npm init
after that install npm by using
npm install

Related

When using npm, commands fail due to cache access restriction/lock (errno EBUSY -4082)

Problem
I've been running into what appears to be a directory access issue in Windows when attempting to use npm. Having tried numerous suggestions from various other SO questions and answers, I thought I'd see if anyone might have suggestions or solutions based on log the output.
I'm continuously running into the error anytime I attempt an npm operation, including install (global or local), uninstall, update, or executing tools such as electron-packager as shown in the package.json scripts section, below the error itself.
Information
Operating system: Windows 10 (Build 19043)
node version: v18.3.0
npm version: 8.12.1
The error output itself is typically
:
npm ERR! code EBUSY
npm ERR! syscall rename
npm ERR! path C:\Users\<username>\AppData\Local\npm-cache\_cacache\tmp\a870f111
npm ERR! dest C:\Users\<username>\AppData\Local\npm-cache\_cacache\content-v2\sha512\d3\23\a585f82ed54ccfe948a39da16e212d9b112d87f43f74100e4e56c7f688e670ed506b8e7b57284c0a7c268503abcc5569023fcaa73f00b1c4f7670d5c2537
npm ERR! errno -4082
npm ERR! EBUSY: resource busy or locked, rename 'C:\Users\<username>\AppData\Local\npm-cache\_cacache\tmp\a870f111' -> 'C:\Users\<username>\AppData\Local\npm-cache\_cacache\content-v2\sha512\d3\23\a585f82ed54ccfe948a39da16e212d9b112d87f43f74100e4e56c7f688e670ed506b8e7b57284c0a7c268503abcc5569023fcaa73f00b1c4f7670d5c2537'
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\<username>\AppData\Local\npm-cache\_logs\2022-06-04T18_34_40_792Z-debug-0.log
Full log output: PasteBin
package.json
{
"name": "MyElectronApp",
"productName": "MyElectronApp",
"desktopName": "MyElectronApp",
"version": "1.0.0",
"description": "Foobar",
"main": "app.js",
"repository": "https://github.com/",
"keywords": [],
"author": "cognophile",
"license": "GNU General Public License v3.0",
"files": [
"app.js",
"assets/styles.css",
"resources/icon.png",
"resources/icon.ico",
"resources/icon.icns"
],
"scripts": {
"start": "npx electron .",
"build": "npm run build:macos && npm run build:linux && npm run build:windows",
"build:macos": "npx electron-packager . --overwrite --asar --out=dist --ignore='^media$' --prune --platform=darwin --arch=x64 --icon=resources/icon.icns --app-bundle-id=com.cognophile.myelectronapp --app-version=$npm_package_version && cd dist/MyElectronApp-darwin-x64 && zip -ryXq9 ../MyElectronApp-macos-${npm_package_version}.zip MyElectronApp.app",
"build:linux": "npx electron-packager . --overwrite --out=dist --ignore='^media$' --prune --platform=linux --arch=x64 --icon=resources/icon.png --app-bundle-id=com.cognophile.myelectronapp --app-version=$npm_package_version && cd dist/MyElectronApp-linux-x64/ && zip -ryq9 ../MyElectronApp-linux-${npm_package_version}.zip *",
"build:windows": "npx electron-packager . --overwrite --asar --out=dist --ignore='^media$' --prune --platform=win32 --arch=ia32 --icon=resources/icon.ico --version-string.ProductName=$npm_package_productName --app-version=$npm_package_version && cd dist/MyElectronApp-win32-ia32 && zip -ryq9 ../MyElectronApp-windows-${npm_package_version}.zip *"
},
"devDependencies": {
"electron": "^13.6.6",
"electron-builder": "^22.4.1",
"electron-packager": "^14.2.1"
},
"dependencies": {
"about-window": "^1.15.2"
}
}
Trying to run the scripts results in the same error, with differing details. For example, trying to execute the npm start script. The same is true for npm run build:windows, but the unfetchable package URL in the error is https://registry.npmjs.org/electron-packager
❯ npm start
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
> MyElectronApp#1.0.0 start
> npx electron .
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm ERR! code EBUSY
npm ERR! syscall rename
npm ERR! path C:\Users\<username>\AppData\Local\npm-cache\_cacache\tmp\01286790
npm ERR! dest C:\Users\<username>\AppData\Local\npm-cache\_cacache\content-v2\sha512\1b\71\c52f6c1e74e5c3c22e0f872bae840fa8e460c356b5c1f807c437a1f8cad2b7bfeb884bb387cbd8012a08d5deaa4b1395f5d4d1cfbc00cfd1b4f5c5e201e3
npm ERR! errno EBUSY
npm ERR! Invalid response body while trying to fetch https://registry.npmjs.org/electron: EBUSY: resource busy or locked, rename 'C:\Users\<username>\AppData\Local\npm-cache\_cacache\tmp\01286790' -> 'C:\Users\<username>\AppData\Local\npm-cache\_cacache\content-v2\sha512\1b\71\c52f6c1e74e5c3c22e0f872bae840fa8e460c356b5c1f807c437a1f8cad2b7bfeb884bb387cbd8012a08d5deaa4b1395f5d4d1cfbc00cfd1b4f5c5e201e3'
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\<username>\AppData\Local\npm-cache\_logs\2022-06-04T19_08_01_775Z-debug-0.log
Attempted solutions
I've tried a number of suggestions from a variety of sources, including (npm ERR! code ENOENT npm ERR! syscall rename [StackOverflow]):
Clearing the cache with npm cache clean --force then reinstalling (npm install)
Verifying the cache with npm cache verify then reinstralling (npm install)
Removing node_modules and package-lock.json, clearing the cache, and reinstalling
Removing read-only checkbox from project folder and cache folder (right-click > properties) which seems to immediately get reset
I've tried these in dedicated PowerShell terminals (non-admin and admin), and the integrated terminal in Visual Studio Code, all having the same result. I've also tried:
Repairing the nodejs installation via the installer
Uninstalling nodejs and removing node/npm related files and directories, restarting the PC, and reinstalling nodejs and attempting npm install in a fresh PowerShell terminal
Rebooting to ensure no other processes are using these directories (such as vscode or another terminal instance)
Closing anti-virus program (not attempted a full uninstall) and trying the above solutions
I suspect this relates to permissions on the cache directories, judging by the error message, but since it is npm which creates those directories after the npm cache clean, I'm not sure I understand what more is needed, and am naturally hesitant to change directory permissions (e.g. NodeJS change file and folder permissions [StackOverflow]) until having received advice.
Thanks in advance!

Git Error -4058 while trying to npm install nw-builder

I just created a new folder on my Desktop and loaded it to VSCode so I can start building/learning about NW.js. The first thing I've done was to open VSCode Terminal and execute npm init -y, then I've proceeded to run npm install nw#sdk. No error whatsoever.
Now my new folder has a package.json, a package-lock.json, and node_modules folder.
package.json content:
{
"name": "rename-merra-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"nw": "^0.62.1-sdk"
}
}
When I try to run npm install nw-builder --save-dev as the reference suggests # https://www.npmjs.com/package/nw-builder, I got the following error:
npm ERR! code ENOENT
npm ERR! syscall spawn git
npm ERR! path git
npm ERR! errno -4058
npm ERR! enoent An unknown git error occurred
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\Misharin\AppData\Local\npm-cache\_logs\2022-03-23T03_41_13_504Z-debug-0.log
The .log file can be found here: https://pastebin.com/cZAmugRF
I've tried the following:
Restart VSCode
Restart My Computer
Run npm install (Up to date, 120 packages, version 8.5.5)
Run npm outside VSCode, directly on the prompt (same error)
Delete package-lock.json
Reinstall NodeJS (17.8.0)
Install an older version of NodeJS (17.7.1)
Search for node.js running in the background (there is none)
Disable Windows Security
Run npm cache clear --force
Does anyone have any idea how to solve this error?
Maybe one of the git links (https://registry.npmjs.org/nw-builder) from the nw-builder package is down/offline? In that case, is there any way around it so I can start building with nw.js?
Thank you for your help!
Make sure you have Git installed:
https://git-scm.com
You'll likely want to change your code to:
"devDependencies": {
"nw": "0.62.1-sdk"
}
The ^ can download the normal version if it was published after the sdk version.
I haven't used nw-builder, but from my understanding, it hasn't received any updates in several years. There is a GitHub issue related to this:
https://github.com/nwjs-community/nw-builder/issues/530
Finally, here are instructions for how to manually create your own build:
https://gitlab.com/TheJaredWilcurt/battery-app-workshop
More tutorials are at:
https://nwutils.io

npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\...\package.json'

I'm doing a tutorial on VueJS. I am completely new to this, so not enitrely sure what I am doing.
I followed all instructions, installed all packages, here is the check I made in terminal in VSCode:
PS C:\Users\...\Documents\Vue - Getting Started> node --version
v12.18.0
PS C:\Users\...\Documents\Vue - Getting Started> npm --version
6.14.5
PS C:\Users\...\Documents\Vue - Getting Started> vue --version
#vue/cli 4.4.1
However, whenever I try to npm run serve as it's shown in the tutorial, it shows an error stating that a package.json is missing:
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\...\package.json'
I checked, and indeed, I don't have a file called package.json in my user folder. I only have a file called package-lock.json.
I also noticed, that on the tutorial video, the terminal has something like 1: node, while in mine, I can see 1: powershell. Here is the screenshot:
screenshot from terminal
What am I missing? Thank you
As suggested by El, I did npm init and created a package.json file in my project folder. Inside, I added the bit suggested by El. The whole package.json file now looks like this:
{
"name": "package.json",
"version": "1.0.0",
"description": "package json",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"serve": "node index.js"
},
"author": "",
"license": "ISC"
}
And I am now getting this error:
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! package.json#1.0.0 serve: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the package.json#1.0.0 serve script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
I think there's no need to explain Nodejs ENOENT error with such a self-explanatory error message: no such file or directory which simply means index.js or any file that you want to run with npm or node isn't in the current directory.
First you need to check to see if you are in the root of your project then in the root of your project you need to have a config file that is package.json for JavaScript(Nodejs, react, typescript and so on) projects.
So for making that config file you can use npm init command and it will ask you predefined questions about your projects.
for starting or serving your project you must have a script tag like this in your package.json file:
'scripts':{
'serve': 'node index.js',
}
then you can use npm run serve command in the root of your project to run serve command of your package.json file.
In case of VueJS, which I am not familiar with, I think you have a index.html file in the root directory of your project and aslo as I know you have vue installed on your machine. I guess you need to replace node index.js with following command to serve your Vue application:
'scripts':{
'serve': 'vue index.html',
}
and run npm run serve.
I fixed this problem with those commands:
// Locate to the folder, where the "node_modules" directory is stored
rm node_modules
npm i
deleted the project folder and then creating vue project
vue create my-project
This is how it worked for me

Getting npm ERR! ENOTDIR: not a directory while installing package which depends on another

Note: I have latest npm and node versions. I have tried the answers provided in npm install error ENOTDIR but didn't work for me.
I need to install 2 npm modules got as .tgz packages on NodeRed
1. x.tgz
2. y.tgz
I could install the first package using npm install path/to/x.tgz
I used the same command npm install path/to/y.tgz command but I am getting following error.
malintha#malintha-VirtualBox:~/.node-red$ sudo npm install path/to/y.tgz
npm ERR! path path/to/y.tgz/x.tgz
npm ERR! code ENOTDIR
npm ERR! errno -20
npm ERR! syscall stat
npm ERR! ENOTDIR: not a directory, stat 'path/to/y.tgz/x.tgz'
According to the error log, y module is looking for x.tgz inside it. Then I checked the package.json of y.tgz artefact.
I can see it has x.tgz as the dependency inside it, but it don't have x.tgz inside it.
"dependencies": {
"#abc/pqr": "file:x.tgz",
"ajv": "^6.5.1",
"debug": "^3.1.0"
}
According to the instructions, it should be fine if I install the x.tgz and then y.tgz. I could install these x and y some time back but now I cannot install it.
What might be the root cause for this issue?
Is this npm and node versions related issue?
I'm re-writing this answer after deleting my old answer. I tested it with and node v11.6.0 and npm v4.5.0-next.0 on Linux.
To install y.tgz, I tried as below:
I copied both tgz files in the same directory.
I modified package.json of y.tgz as below:
"dependencies": {
"#abc/pqr": "file:../x.tgz",
"ajv": "^6.5.1",
"debug": "^3.1.0"
}
dependencies supports file: + relative path or absolute path.
So, you can choose anyone as your development condition.

Can't install any npm packages

I can't install any npm packages. I type in npm install lodash and I get:
npm WARN webdev#1.0.0 No description
npm WARN webdev#1.0.0 No repository field.
npm ERR! path C:\Users\Blake\Desktop\webdev\node_modules\lodash
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename 'C:\Users\Blake\Desktop\webdev\node_modules\lodash' -> 'C:\Users\Blake\Desktop\webdev\node_modules\.lodash.DELETE'
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\Blake\AppData\Roaming\npm-cache\_logs\2018-03-15T21_28_45_978Z-debug.log
My package.json file looks like:
{
"name": "webdev",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
I'm not sure what is wrong. I've tried uninstalling and reinstalling node.js. My npm version is 5.6.0. This happens with every package I've tried to install. Please help, I've been trying to fix this for hours to no avail.
EDIT: I fixed it! The absolute nightmare of a program, MalwareBytes Antimalware was blocking it. I quit out of MalwareBytes and now it is working. Not the first time that program has messed up my coding.
Delete package.json and package-lock.json file, use npm init and try again.
Probably directory node_modules doesnt exist in your project working directory
I would make sure you have npm installed locally in your working directory by running npm init. I would also try re-installing npm.
EDIT:
Remove MalwareBytes Anti-Malware.

Resources