Error given in react-native when npm start - node.js

I am using
Node - v10.6.0
Npm version -4.6.1
When i tried to execute the commad npm start under my project folder, it is giving an error
my_app#0.1.0 start /mnt/E/react_native/my_app
react-native-scripts start
sh: 1: react-native-scripts: Permission denied
npm ERR! code ELIFECYCLE
npm ERR! errno 126
npm ERR! my_app#0.1.0 start:react-native-scripts start
npm ERR! Exit status 126
npm ERR!
npm ERR! Failed at the my_app#0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Please help to rectify the issue

I think you are running your code on MAC. If yes then please try running below command:
sudo chown -R username:groupname directory
where "username" is your current user name, "groupname" is your primary group and "directory" is your project directory path.
Afterwards remove node_modules folder and try below commands:
npm install
npm start

I encountered the same issue, Surprisingly it works fine in Windows but failed in Linux giving the same error. Follow below step to resolve this issue.
you need to change package.json file inside your project folder like below instead of default value of "start": "react-scripts start"
"scripts": {
"start": "node ./node_modules/react-scripts/bin/react-scripts.js start" }

Try running:
sudo sysctl -w fs.inotify.max_user_instances=1024
sudo sysctl -w fs.inotify.max_user_watches=12288
before
npm start
This will temporarily increase the number of files that the development server is able to monitor for changes. This solution is specific for Ubuntu/Linux - the macOS equivalent is "kern.maxfiles" and "kern.maxfilesperproc"

If you haven't installed webpack-dev-server please do it by issuing the below command
npm install -g webpack webpack-dev-server
In case if you have already done it, try deleting your node_modules directory and run a fresh npm install before you execute your react-native-scripts start command.
Hope this helps.

You may not have necessary permissions, so you see:
sh: 1: react-native-scripts: Permission denied
Try starting it with :
sudo react-native-scripts start

I was having this issue. It was running after executing sudo chmod -R 755 .

I solved such a problem by making sure that my react-script binary was executable.
$ chmod +x node_modules/.bin/react-scripts

Related

Your cache folder contains root-owned files

Trying to run npm ci on a git deployment branch for my website but receiving the following error;
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /home/storm/.npm
npm ERR! errno -13
npm ERR!
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR!
npm ERR! To permanently fix this problem, please run:
npm ERR! sudo chown -R 1010:1010 "/home/storm/.npm"
I tried running the command it suggests but this doesn't work because there's no such file or directory of "/home/storm/.npm"
I can't find any answers online! Please help
There are multiple ways to solve the described issue. It depends on how you run npm.
Option 1:
Adapt the access rights on the npm cache files / folder. Just run the suggested command where 'storm' is your user name and '1010' are your user ID and group ID. (User ID and group ID sometimes differ.)
sudo chown -R 1010:1010 "/home/storm/.npm"
Option 2:
Remove the npm cache by running the following command:
sudo npm cache clean --force
Option 3:
Instruct npm to user another directory for caching (avoid using the default npm cache folder). Run the following command before running npm.
export npm_config_cache=/path/to/cache
In my case I ran yarn / npm in a CI/CD pipeline on a Jenkins agent and faced the same issue. Option 3 worked for me. I adapted my pipeline and replaced the command
gradle testAndCoverageWithYarn
with
export npm_config_cache=npm-cache && gradle testAndCoverageWithYarn
(The gradle task testAndCoverageWithYarn calls yarn / npm.)
I had this issue and this command worked for me:
sudo npm cache clean --force
If this issue sill occured try :
sudo chown -R 1010:1010 "/home/storm/.npm"
Good Luck ;-) I hope it works for You! Watch out for typos ..

why does "npm run build" produce error "react-scripts Permission denied"?

I'm on Ubuntu 18.04, logged in as root. The group:owner of /root/.npm is root:root, recursively, and all permissions are 777, recursively. If I cd to the React folder:
cd /var/lib/jenkins/workspace/MedAverter/medaverter-front
And set all permissions of that folder to 777, recursively and then run
npm run build
I get error:
[[1;34mINFO[m] Running 'npm run build' in
/var/lib/jenkins/workspace/MedAverter/medaverter-front
[[1;34mINFO[m] [[1;34mINFO[m] > medaverter-front#0.1.0 build
/var/lib/jenkins/workspace/MedAverter/medaverter-front
[[1;34mINFO[m] > react-scripts build [[1;34mINFO[m]
[[1;31mERROR[m] sh: 1: react-scripts: Permission denied
[[1;31mERROR[m] npm ERR! code ELIFECYCLE [[1;31mERROR[m] npm ERR!
errno 126 [[1;31mERROR[m] npm ERR! medaverter-front#0.1.0 build:
react-scripts build [[1;31mERROR[m] npm ERR! Exit status 126
[[1;31mERROR[m] npm ERR! [[1;31mERROR[m] npm ERR! Failed at the
medaverter-front#0.1.0 build script.
I've been googling for a solution for hours with no luck. It builds fine under Windows 10.
Suggestions?
You may need to run
$ npm config set user root
I ran into that issue once building from a node docker file
Since I am unable to comment.
Personally, I have followed this answer and chosen Solution 2.
After reading more about this you shouldn't be giving npm sudo/root permissions. You are putting way too much faith in the scripts. Rather update your npm by following that guide and you will no longer have that issue.
Did that for my raspberry pi.
I finally solved this problem. The solutions is shown here:
"npm run build" = "react-scripts: Permission denied"
The main problem was that user jenkins was trying to run things owned by user root. So you need to do a
sudo chown -R jenkins medaverter-front
you also need to put sudo in front of the chmod as in
sudo chomod -R 777 medaverter-front
Even though I was logged in as root, somehow that was not enough. I don't understand why not but there were definitely some items whose permissions were not being changed.

nodemon not working: -bash: nodemon: command not found

I'm on a Mac running El Capitan. I have node v5.6.0 and npm v3.6.0.
When I try to run nodemon, I get:
-bash: nodemon: command not found
I thought this may mean that I didn't have nodemon installed, so when I tried to install it using...
sudo npm install -g nodemon
...I get this:
npm ERR! Darwin 15.2.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "nodemon"
npm ERR! node v5.6.0
npm ERR! npm v3.6.0
npm ERR! path /usr/local/bin/nodemon
npm ERR! code EEXIST
npm ERR! Refusing to delete /usr/local/bin/nodemon: ../lib/node_modules/nodemon/nodemon.js symlink target is not controlled by npm /usr/local
npm ERR! File exists: /usr/local/bin/nodemon
npm ERR! Move it away, and try again.
npm ERR! Please include the following file with any support request:
npm ERR! /Users/brianeoneill/npm-debug.log
If it makes a difference, I'm trying to run nodemon on a project that uses Express v4.13.1
Thanks for any help you can offer!
I tried the following, and none worked:
npm uninstall nodemon
sudo npm uninstall -g nodemon
What did work was:
sudo npm install -g --force nodemon
If you want to run it locally instead of globally, you can run it from your node_modules:
npx nodemon
From you own project.
npx nodemon [your-app.js]
With a local installation, nodemon will not be available in your system path. Instead, the local installation of nodemon can be run by calling it from within an npm script (such as npm start) or using npx nodemon.
OR
Create a simple symbolik link
ln -s /Users/YourUsername/.npm-global/bin/nodemon /usr/local/bin
ln -s [from: where is you install 'nodemon'] [to: folder where are general module for node]
node : v12.1.0
npm : 6.9.0
I'm using macOS/Linux, the solution that works for me is
npx nodemon index.js
I have tried every possibility, like uninstalling and installing nodemon, installing nodemon globally. restart the terminal, but it won't work.
don't try such things to waste your time.
in Windows OS run:
npx nodemon server.js
or add in package.json config:
...
"scripts": {
"dev": "npx nodemon server.js"
},
...
then run:
npm run dev
I had the same exact problem, expect for Windows OS.
For me, running
npm install -g nodemon --save-dev
(note the -g) worked.
Maybe somebody else who has this problem on Windows will have the same solution.
FOR WINDOW USERS
I tried every possible way but nothing worked for me.
What worked was:-
npx nodemon server
FOLLOWING WILL BE THE OUTPUT:-
For mac Users, use npx nodemon index.js
...
"scripts": {
"start": "npx nodemon index.js"
},
...
> my-project#1.0.0 start
> npx nodemon index.js
Need to install the following packages:
nodemon
Ok to proceed? (y)
[nodemon] 2.0.13
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node index.js`
Server Started on Port 8000
sudo npm install nodemon --save-dev
Next package.json on and
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon app.js"
}
Type on terminal (command prompt)
npm start
Install nodemon:
sudo npm install -g nodemon
Run server:
sudo nodemon server.js
I ran into the same problem since I had changed my global path of npm packages before.
Here's how I fixed it :
When I installed nodemon using : npm install nodemon -g --save , my path for the global npm packages was not present in the PATH variable .
If you just add it to the $PATH variable it will get fixed.
Edit the ~/.bashrc file in your home folder and add this line :-
export PATH=$PATH:~/npm
Here "npm" is the path to my global npm packages . Replace it with the global path in your system
In macOS,
I fixed this error by installing nodemon globally
npm install -g nodemon --save-dev
and by adding the npm path to the bash_profile file. First, open bash_profile in nano by using the following command,
nano ~/.bash_profile
Second, add the following two lines to the bash_profile file (I use comments
"##" which makes it bash_profile more readable)
## npm
export PATH=$PATH:~/npm
For nodemon: not found command
I tried with many links but was not working then i tried with the below steps it worked fine.
Follow this step it worked for me.
step1 : sudo su
step2 : npm install -g nodemon --save-dev
It is working fine.
Just in case for those using Windows, you don't need sudo
npm i -g nodemon
sudo su
then
npm install nodemon
worked for me
Just writing what did worked for me - (on Windows machine, installing node locally to the project)
if you do not want to install it globally (i.e without -g flag) you have to use
npx nodemon app
where app is your app.js is your program file to launch.
Make sure you own root directory for npm so you don't get any errors when you install global packages without using sudo.
procedures:-
in root directory
sudo chown -R yourUsername /usr/local/lib/node_modules
sudo chown -R yourUsername /usr/local/bin/
sudo chown -R yourUsername /usr/local/share/
So now with
npm i npm -g
you get no errors and no use of sudo here.
but if you still get errors confirm node_modules is owned again
/usr/local/lib/
and make sure you own everything
ls -la
now
npm i -g nodemon
will work!
Since Node v18.11.0 there is running in 'watch' mode using
node --watch
which restarts the process when an imported file is changed.
https://nodejs.org/en/blog/release/v18.11.0/
Following commands worked for me in my case
Open Windows Powershell and Run series of following Commands,
Get-ExecutionPolicy -List
Set-ExecutionPolicy Unrestricted
*Press Y for YES*
Set-ExecutionPolicy Unrestricted -Force
Here you Go.
In Windows git bash, I fixed it by restarting git bash
Put --exec arg in single quotation.
e.g. I changed "nodemon --exec yarn build-langs" to "nodemon --exec 'yarn build-langs'" and worked.

nodemon not found in npm

I have a problem: nodemon does not run off the npm script (e.g. npm start),
but if nodemon is called on the command line outside the npm script, nodemon runs as normal.
$ nodemon server.js
14 Feb 22:59:51 - [nodemon] v1.3.7
14 Feb 22:59:51 - [nodemon] to restart at any time, enter `rs`
14 Feb 22:59:51 - [nodemon] watching: *.*
14 Feb 22:59:51 - [nodemon] starting `node server.js`
How it is called in npm script:
package.json
{
...
"scripts": {
"start": "nodemon server.js"
}
}
When npm start script is run:
$ npm start
> aaa#0.0.1 start /home/akul/Documents/aaa
> nodemon server.js
sh: 1: nodemon: not found
npm ERR! Linux 3.13.0-45-generic
npm ERR! argv "node" "/home/akul/npm-global/bin/npm" "start"
npm ERR! node v0.12.0
npm ERR! npm v2.5.0
npm ERR! code ELIFECYCLE
npm ERR! aaa#0.0.1 start: `nodemon server.js`
npm ERR! Exit status 127
npm ERR!
npm ERR! Failed at the aaa#0.0.1 start script 'nodemon server.js'.
npm ERR! This is most likely a problem with the aaa package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! nodemon server.js
npm ERR! You can get their info via:
npm ERR! npm owner ls aaa
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/akul/Documents/aaa/npm-debug.log
I've been looking for a solution, but have not found one.
You can resolve this problem by adding nodemon to your package.json:
npm install nodemon --save-dev
The problem happens when nodemon does not exist in /node_modules/.bin.
Added --save-dev since it's required during development only.
Try to check installed global packages npm list -g --depth=0. If you will not find nodemon, - install it with flag -g or --save-dev. Don't install nodemon with flag --save, because nodemon uses only for development.
under your current project directory, run
npm install nodemon --save //save in package.json so that the following code cam find your nodemon
then under "scripts" in your package.json file, add "start": "nodemon app.js" (or whatever your entry point is) so it looks like this:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon app.js"
}
and then run
npm start
That avoids complicate PATH settings and it works on my mac
hope can help you ;)
Install nodemon globally using following command. It works on my computer, and I'm sure it will work on your system also.
npm install nodemon -g --save
Sometimes you should have the permission to install it globally. It can be easily done by using following command.
In LINUX UBUNTU:
sudo npm install nodemon -g --save
In Fedora:
a) su
b)npm install nodemon -g --save
Try to install nodemon globally.
sudo npm install -g nodemon
Here's how I fixed it :
When I installed nodemon using : npm install nodemon -g --save , my path for the global npm packages was not present in the PATH variable .
If you just add it to the $PATH variable it will get fixed.
Edit the ~/.bashrc file in your home folder and add this line :-
export PATH=$PATH:~/npm
Here "npm" is the path to my global npm packages . Replace it with the global path in your system
heroku runs in a production environment by default so it does not install the dev dependencies.
if you don't want to reinstall nodemon as a dependency which I think shouldn't because its right place is in devDependencies not in dependencies.
instead, you can create two npm script to avoid this error by running nodemon only in your localhost like that:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js",
"start:dev": "nodemon --watch"
},
and when you want to run the project locally just run in your terminal npm run start:dev and it will load app.js by nodemon.
while in heroku npm start runs by default and load app.js from a normal node command and you get rid of that error.
You have to simply installed it globally.
npm install -g nodemon
This solution had worked for me:
I assume that you have installed nodemon globally. If it's done follow this steps:
open your .bash_profile file:
nano .bash_profile
past this to add a new alias in your bash profile:
alias nodemon='~/.npm-global/lib/node_modules/nodemon/bin/nodemon.js'
Now you can use nodemon command anywhere.
sudo npm install nodemon -g --save
Finally this worked for me. I hope this must work for others too
My nodemon vanished after installing babel (why?).
Tried a lot of stuff.
Here is how I solved it:
sudo npm i -g nodemon
Just reinstall it with sudo. Yeah.
For Visual Studio Code editor with Windows Sub-system for Linux, i.e, WSL mode:
sudo npm install nodemon -g
for global use of nodemon.
I had the same problem and was able to solve it. This was me error:
npm install -g nodemon
npm WARN checkPermissions Missing write access to /usr/local/lib
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents#~2.3.2 (node_modules/nodemon/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents#2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib'
npm ERR! { [Error: EACCES: permission denied, access '/usr/local/lib']
npm ERR! stack:
npm ERR! 'Error: EACCES: permission denied, access \'/usr/local/lib\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/rayani00/.npm/_logs/2022-01-03T17_50_15_842Z-debug.log
(base) rayani00#rayani00:~/Bureau/my-express-server$ npm cache clear --force
npm WARN using --force I sure hope you know what you are doing.
To solve it i just aded a sudo for the nodemon installation :
sudo npm install -g nodemon
nodemon server.js
That worked for me!
NPM is used to manage packages and download them. However, NPX must be used as the tool to execute Node Packages
Try using NPX nodemon ...
Hope this helps!
This worked for me ...
Install nodemon as a local dev dependency
npm install --save-dev nodemon
Add script to your application package.json to start the application.
"scripts": {
"start": "nodemon app.js"
},
Start nodemon with npm start
$ npm start
> node-rest-demo#1.0.0 start node-rest-demo
> nodemon app.js
[nodemon] 1.19.4 [nodemon] to restart at any time, enter `rs` [nodemon] watching dir(s): *.* [nodemon] watching extensions: js,mjs,json [nodemon] starting `node app.js` Starting server ...
I faced a similar issue, but then checked .npmrc file and there was incorrect password in that that caused the connection failure and there fore yarn --verbose returned Bad request error. After correcting the password, the packages were added successfully.
I found a very easy solution.
Simply delete the npm and npm cache folder from your pc.
Reinstall it again, but the mistake that many of us make is not installing npm globally.So:
npm i -g npm
And then, install nodemon globally:
npm i -g nodemon
Now,nodemon works globally, even without using the command:
npx nodemon <yourfilename>.js
npx nodemon (app.js) worked for me and nodemon (app.js) did not.
I updated node.js to the latest version and now both are working.
I had this problem and even after I have used the command npm install nodemon --save in my application, I still had problem with nodemon.
I just resolved after I installed nodemon globally, using the command:npm install nodemon -g
Had the same problem otherwise was just working fine a day ago.
Very simple fix
first check if nodemon exists on your system globally or not
To check
npm list -g --depth=0
If you don't see then install
it npm install -g nodemon (g stands for globally)
If you see it still doesn't work then you need to configure environment variable
I use Windows OS. On Windows navigate to
Control panel>System>Advanced System Settings>Environment Variables>double-click on PATH
Now check if you have this PATH C:\Users\yourUsername\AppData\Roaming\npm
If not, you will see some existing paths, just append to it separating with semicolon. That's it! Worked for me.
For me node was installed in C:..\Roaming\npm and for you if the PATH is different, you will put in whatever applcable.
First install nodemon to your working folder by
npm install nodemon
Add the path of nodemon to the path variable of Environment Variable of System environment.
In my case the path of nodemon was.
C:\Users\Dell\Desktop\Internship Project\schema\node_modules\.bin
It worked for me.
You can always reinstall Node.js. When I had this problem, I couldn't fix it, but all I did was update the current version of Node. You can update it with this link: https://nodejs.org/en/download/
I wanted to add how I fixed this issue, as I had to do a bit of mix and match from a few different solutions. For reference this is for a Windows 10 PC, nodemon had worked perfectly for months and then suddenly the command was not found unless run locally with npx.
Here were my steps -
Check to see if it is installed globally by running npm list -g
--depth=0, in my case it was installed, so to start fresh...
I ran npm uninstall -g nodemon
Next, I reinstalled using npm install -g --force nodemon --save-dev (it might be recommended to try running npm install -g nodemon --save-dev first, go through the rest of the steps, and if it doesn't work go through steps 2 & 3 again using --force).
Then I checked where my npm folder was located with the command npm config get prefix, which in my case was located at C:\Users\username\AppData\Roaming\npm
I modified my PATH variable to add both that file path and a second entry with \bin appended to it (I am not sure which one is actually needed as some people have needed just the root npm folder and others have needed bin, it was easy enough to simply add both)
Finally, I followed similar directions to what Natesh recommended on this entry, however, with Windows, the .bashrc file doesn't automatically exist, so you need to create one in your ~ directory. I also needed to slightly alter how the export was written to be export PATH=%PATH%;C:\Users\username\AppData\Roaming\npm; (Obviously replace "username" with whatever your username is, or whatever the file path was that was retrieved in step 4)
I hope this helps anyone who has been struggling with this issue for as long as I have!
--save, -g and changing package.json scripts did not work for me. Here's what did: running npm start (or using npx nodemon) within the command line. I use visual studio code terminal.
When it is successful you will see this message:
[nodemon] 1.18.9
[nodemon] to restart at any time, enter rs
[nodemon] watching: .
[nodemon] starting node app.js
Good luck!
In my case nodemon needed to be installed globally:
npm i nodemon -g --save
I tried to list global packages using npm list -g --depth=0, but couldn't find nodemon.
Hence, tried installing it using global flag.
sudo npm install nodemon -g
This worked fine for me.
Instructions for Windows,
Open Command Prompt.
type npm i -g nodemon --save
"--save" is to save the addition of this node package in your project's package.json file
I my case:
npm install nodemon
With out any flags etc.
for linux try
sudo npm install -g nodemon
for windows
open powershell or cmd as administration
npm install -g nodemon
I got this issue while deploying on Heroku.
The problem is on Heroku the don't include the devDependencies on its own.
To fix this issue, simply run the command in the terminal:
heroku config:set NPM_CONFIG_PRODUCTION=false
Make sure to include nodemon in your devDependencies
"devDependencies": {
"nodemon": "^2.0.6"
}
Incase your error is not in Heroku
I would suggest uninstalling nodemon and then reinstalling it
https://www.npmjs.com/package/nodemon
Or try changing the script
"scripts": {
"start": "nodemon fileName.js",
"start:dev": "nodemon fileName.js"
}
Hope it would help :)

npm can't find package.json

I'm trying to install the dependencies of some example: npm's express 2.5.8 that I've downloaded, but all of the apps throw the same error:
c:\node\stylus>npm install -d
npm info it worked if it ends with ok
npm info using npm#1.1.1
npm info using node#v0.6.11
npm ERR! Couldn't read dependencies.
npm ERR! Error: ENOENT, no such file or directory 'c:\node\stylus\package.json'
npm ERR! You may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-#googlegroups.com>
npm ERR!
npm ERR! System Windows_NT 6.1.7600
npm ERR! command "C:\\Program Files (x86)\\nodejs\\\\node.exe" "C:\\Program File
s (x86)\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "-d"
npm ERR! cwd c:\node\stylus
npm ERR! node -v v0.6.11
npm ERR! npm -v 1.1.1
npm ERR! path c:\node\stylus\package.json
npm ERR! code ENOENT
npm ERR! message ENOENT, no such file or directory 'c:\node\stylus\package.json'
npm ERR! errno {}
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! c:\node\stylus\npm-debug.log
npm not ok
The blockage appears to be:
no such file or directory 'c:\node\stylus\package.json
Did I miss a step that creates the package.json ?
I'm running:
Windows 7 64 bit
npm 1.1.1
node 6.11
express 2.5.8
I think, npm init will create your missing package.json file. It works for me for the same case.
In your project's folder, you need to initialize the package.json file by running the following in the terminal:
npm init
After that, you should be able to install any packages as you would expect, like express:
npm install express
Shout out to Deepali's answer.
I'll be brief but deadly. :) install -d will not work for you. It's simple. Try
$ npm install -g express
Follwing the below steps you well get package.json file.
npm --version
npm install express
npm init -y
If Googling "no such file or directory package.json" sent you here, then you might be using a very old version of Node.js
The following page has good instructions of how to easily install the latest stable on many Operating systems and distros:
https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
Beginners usually try the npm command from random locations.
After downloading or creating a project, you have to cd into this project folder. Inside is the file package.json.
cd <path_to_project>
npm install
Use the command in win7/win8/win10 (CD) for moving folders:
Enter your projects folder
Run: npm install -d
try re-install Node.js
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo apt-get install -y build-essential
and update npm
curl -L https://npmjs.com/install.sh | sudo sh
Node comes with npm installed so you should have a version of npm. However, npm gets updated more frequently than Node does, so you'll want to make sure it's the latest version.
sudo npm install npm -g
Test:
npm -v //The version should be higher than 2.1.8
After this you should be able to run:
npm install
It may be very evident,
but try to launch CMD (for Windows) from the project folder,
where your package.json file is located.
Do not launch CMD from System or from "Search bar" in Win or
move to your project folder with help of cd command and then launch npm start.
I had a similar problem with npm. The problem was that I had the project inside two folders of the same name. I resolved it by renaming one of the folders to something else (outer folder recommended).
It by itself says that package.json is not available in your project.
So, to create package.json, use the following steps:
open command prompt on your project directory
npm init (it will ask you to enter lots of entries like name, version, desc, etc., enter some random values and click enter).
type yes and click enter
Now try again.
Go inside the project folder and check whether the package.json file does exist.
If you are creating the project using Visual Studio Angular project, make sure you run this command inside the ClientApp Folder. there is a good chance, you could be looking for project.json file outside the ClientApp folder.
if the package.json file in the project directory is missing then you can create it by
npm init.
if the package.json file is already created in the project directory then there is a possibility that you are not running your project from the right path.
Use cd your-project-path in the terminal and then run your project from there.
npm init -y
use this command, it will automatically create package.json file with all your machine information.
I found myself here trying to resolve the same error message:
npm ERR! message ENOENT, no such file or directory 'c:\<some_folder>\package.json'
The error could be due to two reasons:
You do not have the package.json
You have the package.json, but you are running npm start in the wrong folder
To troubleshoot the first cause, you need to create a package.json using:
npm init
To fix the second cause, make sure the folder you are running the npm start command is the same folder as the package.json
I was experiencing this identical error and terminal (foolishly, on my part) was in a parent directory instead of the correct one (where package.json was correctly located).
All I did in terminal was cd [insert correct directory name here, overwriting brackets] and that corrected the problem.
My issue was I didn't have a package.json file for some reason. After I wget this file into my directory, I was able to run npm install
https://raw.githubusercontent.com/twbs/bootstrap/master/package.json
Thank you!
I also tried many options for this. I am also using windows.This command helped and saved my time:
npm install -g npm#lts
ok, try to go to the home "user#user:~$ " (cd + enter key), and npm install -g your your_module.
just install any package you want with -g
npm install -g express
For the following command
sudo npm install react browserify watchify babelify --save-dev
I got same error
saveError ENOENT: no such file or directory, open
'/Users/Path/package.json'
But when I run the command
sudo npm install -gd react browserify watchify babelify --save-dev
then no missing file or directory message appeared.
I have run npm install -y to skip the question step for creating the missing file package.json, y means yes
I was also facing same issue while installing typescript. I just initialized an package.josn file by the following command
npm init -y
And then i installed my typescript
npm install -g -typescript
http://blossomprogramming.blogspot.com/
Please check the directory or the folder in which you're installing your new package.
This happened to me as well,
My whole project was in a subdirectory and I was trying to install in the main directory. After checking the whole thing I found out that I had to install in the subdirectory where my project files and package.json files are located and it's done.
Hope this helps...
the previous tips do not pay attention to any change for me. at the end this works for me:
delete the local repo folder
git clone https ... myRebo.git
npm install
npm start
hope it helps somebody
I got this error because I was trying:
npm install --save-exact express#4.17.1 cors#2.8.5 express-bearer-token#2.4.0
#okta/jwt-verifier#1.0.0 mongoose#5.6.7
which I got from: https://developer.okta.com/blog/2019/09/11/angular-mongodb
I had to separate the packages and run them one by one. I think the backslash caused problem.
Adding -g before the package name worked for me. Looking for documentation to explain why this works..
Generate package.json without having it ask any questions. I ran the below comment in Mac and Windows under the directory that I would like to create package.json and it works
$ npm init -y
Wrote to C:\workspace\package.json:
{
"name": "workspace",
"version": "1.0.0",
"description": "",
"main": "builder.js",
"dependencies": {
"jasmine-spec-reporter": "^4.2.1",
"selenium-webdriver": "^4.0.0-alpha.5"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}

Resources