Error: node_modules directory is missing. Please run `npm install` in your project directory - react-native

expo start
[21:03:34] Starting project at /home/sadaif/Documents/React-Native-App/my
[21:03:35] Expo DevTools is running at http://localhost:19002
[21:03:35] Opening DevTools in the browser... (press shift-d to disable)
[21:03:41] Error: node_modules directory is missing. Please run `npm install` in your project directory.
[21:03:41] Couldn't start project. Please fix the errors and restart the project.
[21:03:41] Set EXPO_DEBUG=true in your env to view the stack trace.
I run this command npm install but noting happened
then i run these commands
rm -rf node_modules
rm package-lock.json
npm cache clear --force
npm install
When I run command expo start then this error show in the terminal .I'm Using first time expo cli i m a beginner so that's why have no idea how to fix this issue if anyone know please help me.

either you are using Mac or Ubuntu the directory you have created the project in needs superuser permissions to modify it.
either run all commands with sudo or change the ownership
sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config
or re-install the node with
npm install -g node#latest --unsafe-perm

Related

Cypress cannot run because this binary file does not have executable permissions

I was trying to create a new project in cypress and I got the following strange error message.
Steps:
npm init -y
npm install cypress --save-dev
I then did npx open cypress and I got the following message from my console
How do I fix this?
Cypress cannot run because this binary file does not have executable permissions here:
/Users/myName/Library/Caches/Cypress/7.5.0/Cypress.app/Contents/MacOS/Cypress
Reasons this may happen:
- node was installed as 'root' or with 'sudo'
- the cypress npm package as 'root' or with 'sudo'
Please check that you have the appropriate user permissions.
You can also try clearing the cache with 'cypress cache clear' and reinstalling.
----------
Platform: darwin (20.5.0)
Cypress Version: 7.5.0
You can do two things:
Run the command npm cypress cache clear and then again install cypress npm install cypress --save-dev and check.
Or, install npm globally without sudo using the command npm install -g. Then create a new folder and then run npm init, npm install cypress --save-dev and npx cypress open.
Do navigate to the cache directory by doing
cd /Users/myName/Library/Caches/
Here you have to delete Cypress directory completely by running the command
rm -rf Cypress
Now head over to your project directory and run the command
npx install cypress
Cypress will be installed in your system again. Next time you won't get any errors.
So, I had a chat with the dev team at Cypress and got the following answer. After reading the logs I had a feeling this might be the root cause. So please check you have the most up to date version of Node.js

Cannot Find Module

I am trying to run react-native start and the following error appears
"Cannot find module 'metro-core'. Run CLI with --verbose flag for more details.
Prior to getting this message, I had a different error message saying modules was not located, so I tried this:
Delete the node_modules folder -
rm -rf node_modules && npm install
Reset packager cache - rm -fr $TMPDIR/react-* or node_modules/react-native/packager/packager.sh --reset-cache
Clear watchman watches - watchman watch-del-all
I just typed in the react-native start and the error message popped up on the simulator, which told me to look at my terminal for the error message.
This is common with NPM. Do not worry. Just follow a few steps and you will get your package.
Step 1: $ npm cache clean --force
Step 2: delete node_modules by $ rm -rf node_modules folder or delete it manually by going into the directory and right-click > delete.
Step 3: npm install
To start again, $ npm start
This worked for me. Hopes it works for you too.
Still, if it is there, kindly checks the error it displays in red and acts accordingly.
Be careful when using rm -rf.
After that,
While working on Unix systems.
Sometimes it may not allow you to install such packages. For that, you need sudo permissions.
Sometimes, the package is installed but only in your local modules, and when you try to import(require) it from outside of the directory, the error occurs.
Sometimes, your compiler read your dependencies, but not able to find this package in that, at that time also you face this error.
Anyways, don't worry. You just have to follow some steps below.
A best practice is to initialize your project using npm init before starting development. This will initialize your project and generate package.json file. (Ignore it if your project have package.json file)
Then, if you want any library as dependencies, try --save with npm install command. This will save your dependency in package.json file.
e.g. npm install metro-core --save
If any package is not found after installing, install it globally by -g flag.
Globally installed packages will be accessible within your system. e.g. npm install metro-core -g.
Note: Unix system needs SUDO permission for installing it globally.
I hope this will help you.
npm install metro-core
use command then run

npm: Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/me/.npm/_cacache/content-v2/sha512/b3/da’

On my Mac, I just updated my working npm version from 5.6 to 6.9 thusly:
sudo npm i -g npm
Then I tried to install cordova like this:
sudo npm install -g cordova
And get
Unhandled rejection Error: EISDIR: illegal operation on a directory,
open '/Users/me/.npm/_cacache/content-v2/sha512/04/89'
npm ERR! cb() never called!
npm ERR! This is an error with npm itself. Please report this error at:
npm ERR! <https://npm.community>
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/me/.npm/_logs/2019-04-02T11_50_57_678Z-debug.log
I tried to downgrade thusly:
sudo npm install -g npm#6.4.1
but this fails with hundreds of lines like this:
npm WARN tar EISDIR: illegal operation on a directory, open '/tmp/npm-30934-a3ac319a/unpack-28da209e/bin/node-gyp-bin'
Unhandled rejection Error: EISDIR: illegal operation on a directory, open '/Users/me/.npm/_cacache/content-v2/sha512/99/72'
I also tried making sure the ownership was correct:
sudo chown -R $(whoami) ~/.npm
There are lots of posts of various EISDIR (error is a directory) problems for other directories (such as /usr/lib/modules), but no solutions seem to work.
Also, the npmrc file does not seem to exist. If I do:
npm config ls -l
globalconfig = "/usr/local/etc/npmrc"
userconfig = "/Users/me/.npmrc"
but neither file exists.
Note, I dont have homebrew, and didnt install it that way (I usually do manual installs).
I also tried this:
sudo npm cache clean -f
This did not help.
What else can I try? should I try deleting the ~/.npm dir?
Looking for a way to uninstall node, I found many old posts with long and sometimes conflicting lists of files to remove. Not sure if this will make it worse.
Any suggestions?
I think I have found a solution. I did the following:
installed node from the Mac pkg installer from https://nodejs.org/en/ This downgraded npm to 6.4.1 which is the version before EISDIR problems start apparently.
chmod -R 777 ~/.npm/_cacache // yes, this is not good
chown -R me ~/.npm/_cacache
After this, I could install cordova using "sudo npm install -g cordova" without errors.
I had the same problem when I upgraded to npm 6.9.0. You have to upgrade node to the last version:
brew reinstall node
At this time I have installed the latest available version for Mac OS Mojave (node: v11.14.0 and npm 6.9.0).
After node upgrade, I was able to install packages globally again.
Changing the ownership of files and then avoiding the use of sudo is a possible workaround for EISDIR with global installs using sudo. I suppose you have installed to default location folder:
sudo chown -R <user> ~/.npm
sudo chown -R <user> /usr/local/lib
sudo chown -R <user> /usr/local/bin
After this sequence, it worked to me.

vue js app yarn serve is failing with exit code 1.?

I am building frontend of a web app using vuejs. till yesterday my app was running fine but all of sudden today yarn serve command is throwing an error.
Error: watch /home/abhey/Documents/abhey/astrix/astrix_final_project/ecommerceFrontend/public ENOSPC
at _errnoException (util.js:1022:11)
at FSWatcher.start (fs.js:1382:19)
at Object.fs.watch (fs.js:1408:11)
at createFsWatchInstance (/home/abhey/Documents/abhey/astrix/astrix_final_project/ecommerceFrontend/node_modules/chokidar/lib/nodefs-handler.js:37:15)
at setFsWatchListener (/home/abhey/Documents/abhey/astrix/astrix_final_project/ecommerceFrontend/node_modules/chokidar/lib/nodefs-handler.js:80:15)
at FSWatcher.NodeFsHandler._watchWithNodeFs (/home/abhey/Documents/abhey/astrix/astrix_final_project/ecommerceFrontend/node_modules/chokidar/lib/nodefs-handler.js:232:14)
at FSWatcher.NodeFsHandler._handleDir (/home/abhey/Documents/abhey/astrix/astrix_final_project/ecommerceFrontend/node_modules/chokidar/lib/nodefs-handler.js:414:19)
at FSWatcher.<anonymous> (/home/abhey/Documents/abhey/astrix/astrix_final_project/ecommerceFrontend/node_modules/chokidar/lib/nodefs-handler.js:462:19)
at FSWatcher.<anonymous> (/home/abhey/Documents/abhey/astrix/astrix_final_project/ecommerceFrontend/node_modules/chokidar/lib/nodefs-handler.js:467:16)
at FSReqWrap.oncomplete (fs.js:153:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I did try to look into the documentation but it was of no use. I also tried to start a new project altogether but it was of no help. any suggestions? if it's of any use I am using Linux Mint 19 as my os.
Well I had the same problem with npm.
You can try to clean the npm cache remove the node module folder and re install the dependencies try this code in your terminal.
cd ~
sudo rm -rf .npm
cd <package folder where node module exist>
npm cache clean
rm -rf node_modules
npm install
try same logic with yarn it will solve your problem.

How to fix EACCES issues with npm install

Some of my node modules get installed but there are always these sort of issues on this particular linux mint machine
npm install
npm ERR! Error: EACCES, open '/home/me/.npm/semver/3.0.1/package/package.json'
npm ERR! { [Error: EACCES, open '/home/me/.npm/semver/3.0.1/package/package.json']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/home/me/.npm/semver/3.0.1/package/package.json',
npm ERR! parent: 'gulp' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
This code fix it for me.
sudo chown -R `whoami` ~/.npm
sudo chown -R `whoami` /usr/local/lib/node_modules
UPDATE. See
this answer
for a better way.
You have to set correct permissions (ownership) so npm can access your (sub)directories with your normal user permissions:
sudo chown -R $USER <directory>
where in your case <directory> is /home/me and -R is for recursive to also change ownership of all your subdirectories, which is exactly what you want. That should fix the EACCESS issue.
Sadly the advise to run the command as root/Administrator is wrong here.
You want to avoid running npm with sudo ever, as recommended by the npm creator Isaac Schlueter:
I strongly encourage you not to do package management with sudo! Packages can run arbitrary scripts, which makes sudoing a package manager command as safe as a chainsaw haircut. Sure, it’s fast and definitely going to cut through any obstacles, but you might actually want that obstacle to stay there.
See here for more details.
Add sudo before npm install . It will permit access to write .
sudo npm install [name of package].
Try to use "sudo npx create-react-app app-name"
it may still show error because some dependencies may be mising but a directory and the necessary files maybe created.
Set the correct permission to access the necessary directories.
In my case (Node & NPM Installation via Brew) on BigSur:
sudo chown -R $USER /Users/YOUR_USERNAME/node_modules
If you are still facing problem after running :
sudo chown -R `whoami` ~/.npm
sudo chown -R `whoami` /usr/local/lib/node_modules
Run the npm install command with :
--unsafe-perm
which will help you in installing the package with out any problem.
To minimize the chance of permissions errors, you can configure npm to use a different directory. In this example, you will create and use hidden directory in your home directory.
Back up your computer.
On the command line, in your home directory, create a directory for global installations:
mkdir ~/.npm-global
Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
In your preferred text editor, open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
On the command line, update your system variables:
source ~/.profile
To test your new configuration, install a package globally without using sudo:
npm install -g jshint
(ref: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally)
Running the code in sudo mode have fixed the problem for me
$ sudo npm install -g nativefier
And if you have related issues like package unmet dependencies check out this link
in windows run cmd as administrator and then try:
npm install -g <package-name>
in mac os or linux try:
sudo npm install -g <package-name>
I understand one might be suspicious about changing the ownership of folders situated in the system files. But it's completely safe, they are meant to host processes that you can use without sudo. So I prefer this solution because it's good and will guarantee compatibility after.
sudo chown -R $USER /usr/local/bin
sudo chmod -R 0775 /usr/local/bin
sudo chown -R $USER /usr/local/lib/node_modules
sudo chmod -R 0775 /usr/local/lib/node_modules
If you installed a new version of node.js, you could still get some error. Try deleting the npm cache:
sudo npm cache clear
To permanently fix this problem, please run:
sudo chown -R 1000:1000 "/home/$USER/.npm"
sudo npm install -g create-react-app
just adding sudo before nmp install will give superuser privilages to run npm and that would not cause any erros while it want to alter a file or access it. well, i hope this might help you!
I had the Similar Problem when I typed:
npm install -g create-react-app
The Terminal replied:
npm ERR! code EACCES
....
So I add "sudo" like This:
sudo npm install -g create-react-app
And problem Solved!! :-)
(So I am agree with "chethan chandan" about using "sudo")