react-native: command not found, tried several solutions, none worked - javascript

I'm working on an ancient react native project, it was absolutely working, then when I wanted to continue working on it, I had this problem,
This is the package.json file.
I ve tried this solution here, deleting the package-lock.json file and re executing
npm install
but it doesn't work for me.

I've tried to uninstall react-native-cli gloabally with
sudo npm uninstall -g react-native-cli
and than install it globally
sudo npm insatll -g react-native-cli
and now it works perfectly :)

Related

Unable to use typescript with expo - "It looks like you're trying to use TypeScript but don't have the required dependencies installed"

I am receiving an error while trying to use Typescript with my existing expo project.
While following the docs, I created a tsconfig.json file in the project root.
When running expo start, I am prompted to install the typescript dependencies. However, after these are successfully installed (tick message appears in console: √ Installed typescript#~4.3.5, #types/react#~17.0.21, #types/react-native#~0.67.6), I receive the following error:
It looks like you're trying to use TypeScript but don't have the required dependencies installed.
Please install #types/react by running:
yarn add --dev #types/react#~17.0.21
If you're not using TypeScript, please remove the TypeScript files from your project and delete the tsconfig.json.
error Command failed with exit code 1.
After following the instructions and running the yarn add .... command, I keep seeing the same error message.
I have tried deleting the node_modules folder and package-lock.json file to no avail. I have also tried following this answer.
Any assistance would be appreciated, thank you.
Seems to be a bug. It works if I install #types/react on the specific version that Expo requests (17.0.21).
yarn add --dev #types/react#17.0.21
Just re-install expo-cli npm install -g expo-cli.
I don't know which of the following worked, but I ran the following commands and the problem went away.
sudo npm install -g expo-cli
sudo npm install -g #types/react
sudo npm install -g #types/react-native
sudo npm install -g typescript
yarn add expo-cli
solved for me.
I had the same issue. I resolved it by :
1- delete the node_modules.
2- update expo to the latest version using npm i -g expo-cli
hope this will help someone
if you installed #types/react remove that from your dev dependencies

Can't install NPM

Image of my terminal in VSCode
I've tried uninstalling/reinstalling node and clearing the cache but I can't seem to figure it out. Any ideas?
I'm on Windows 10 if that helps
Try these:
Delete node_modules folder if you have one.
Delete package.lock.json.
Then...
sudo apt update
sudo apt upgrade
sudo apt install nodejs
npm install
It seems that it's conflicting with chokidar.
First of all you need to delete node_modules and package-lock.json not package.json
and then add cmd
npm install --force
if you are using Ubuntu OS use
sudo npm install
I had a similar issue before and I believe it has to do with your nodejs. I suggest you reinstall your node cause it might solve the issue.
Try purging it
sudo apt-get purge nodejs
Then remove dependencies
sudo apt-get autoremove
Then reinstall
sudo apt install nodejs
Also try updating your chokidar and axios to a newer version, yours is already depreciated.

How to fix "TypeError: fsevents is not a constructor" react error

While staring React app using npm start this error occurred...
I tried below things:
remove node_module package and reinstall
use yarn instead npm
3.update fsevent library using npm
still getting this error
Note: If we create react app fresh/new yarn start will work, but we close the terminal and restart using same thing below error occurred
/Users/nannam/test-app-2/node_modules/chokidar/lib/fsevents-handler.js:28
return (new fsevents(path)).on('fsevent', callback).start();
^
TypeError: fsevents is not a constructor
at createFSEventsInstance (/Users/nannam/test-app-2/node_modules/chokidar/lib/fsevents-handler.js:28:11)
at setFSEventsListener (/Users/nannam/test-app-2/node_modules/chokidar/lib/fsevents-handler.js:82:16)
at FSWatcher.FsEventsHandler._watchWithFsEvents (/Users/nannam/test-app-2/node_modules/chokidar/lib/fsevents-handler.js:252:16)
at FSWatcher. (/Users/nannam/test-app-2/node_modules/chokidar/lib/fsevents-handler.js:386:25)
at LOOP (fs.js:1565:14)
at process._tickCallback (internal/process/next_tick.js:61:11) error Command failed with exit code 1. info Visit
https://yarnpkg.com/en/docs/cli/run for documentation about this
command.
npm audit fix --force
It worked in my case
below steps solved issue :
step 1 : removing node_module and yarn.lock
step 2 : yarn install
step 3 : yarn start
This is a well-documented issue on the react GitHub repo with a couple of options to try.
I solved my error by re-installing the fsevents npm i fsevents, which worked
I solved with
sudo npm i fsevents --unsafe-perm
The #not-a-file gave will work only you can install the fsevents successfully。
but when I do that, I receive an error with this:
Error: EACCES: permission denied, mkdir '/Users/**/node_modules/jest-haste-map/node_modules/fsents/.node-gyp'
So ,I suggest you avoid this by use something like this:
sudo npm i fsevents --unsafe-perm=true --allow-root
And I also find this error may due to node version, when I use node 12,I can not install fsevents successfully , so I use nvm to modify my node version to v11.15.0
👍 Solved it using Yarn's selective dependency resolutions
"resolutions": {
"chokidar": "^3.3.1"
},
as some packages in my dependencies are still on older chokidar versions < 3
I also had the same issue though am using MacOS the issue is kind of bug. I solved this issue by repeatedly running the commands,
sudo npm cache clean --force
sudo npm uninstall
sudo npm install
One time it did not worked but when I repeatedly cleaned the cache and after uninstalling npm, reinstalled npm, the error went off. Am using Angular 8 and this issue is common
Do these simple steps. Run the following
rm -rf node_modules/ package-lock.json
and then
npm i
This worked for me.
For me, downgrading node to v11.15.0 solved the error.
remove node_module and package-lock.json and use yarn instead of npm. This saved me hours.
I deleted the node modules package and reinstalled the node and then executed the node js commands. it worked fine for me.
I FINALLY resolved the issue. The fsevent error occurred right after I installed bootstrap from my VS code terminal. I ended up using the react-bootstrap-github stylesheet code instead and put it in my index.html!
I solved changed my "package.json" using this react-scripts": "2.1.8
I had the same issue. I run the following command and it is working fine now, without using Yarn.
"npm audit fix"
I just solved this issue in node v11.15.0 my solution was: with my "react-scripts" version in "3.0.1" I just update it to "2.1.8" and run npm install after. You can use this version or search for one that works for you. Another option is updating nodejs to the latest version, then remove modules and run npm install.
Currently, we did not found any permanent resolve, but you just create that app again or use yarn package manager to install all modules again in your react app then run yarn start. that's how I solve my issue in react app.
I was able to get it working after running:
$sudo npm install npm#latest -g
I had this issue using the ng serve command. I tried all of the above combinations and none of them seemed to fix this issue permanently. A simple quick fix / get around for me was to close and reopen the terminal.
I had this error TypeError: fsevents is not a constructor and tried all answers (remove node_modules, uninstalling/installing fsevents, sudo npm cache clean --force, sudo npm install/uninstall) listed; but nothing resolved it. For some reason, fsevents is breaking for node version >v10.x.
Regenerating lockfile resolved this issue
npm i --package-lock-only
Run this command
npm install latest-version
Run:
npm audit fix --force
Then, try again.
This often happens due to the continuous update to react and npm-packages.
Try to remove your node_modules
npm uninstall
delete your yarn.lock
this will save tons of time and if you are using npm instead if yarn
always updated.
run yarn install
After trying "npm audit fix --force" did not work , I tried:
Removing node_modules folder
npm i
worked for me

Terminal package-lock.json

I am taking an online coding class and I just started learning my way through Terminal. I was trying to run a npm test but could not figure out why I was getting an error. I looked up different ways to solve it but it only made things worse as I have changed the package.json file into package-lock.json somehow.
Is there a way I could undo this?
Below is the command that I typed:
npm uninstall -g angular-cli
npm uninstall --save-dev angular-cli
npm install -g #angular/cli#latest
It would be greatly appreciated if someone could help me.
Thanks!
Not sure what you are trying to achieve here.
Each part of your command does the following
npm uninstall -g angular-cli
will uninstall the angular command line interface globally (this is what -g does).
npm uninstall --save-dev angular-cli
will uninstall the angular command line interface, and remove from devdependencies within your package.json file.
these two above are the same command apart from the extra arguments.
And then after that you are globally reinstalling the latest angular cli ??
Futhermore for future reference, in order to chain commands you need to add '&&' between the npm commands for one line
Hope that clears something up

How to upgrade React

I've understood that I'm using react.js version 15.6.2. I know this because doing this in my code:
console.log(React.version);
results in this console output:
15.6.2
I want to upgrade to React#^v16.2.0. I tried doing this:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
sudo n latest
But nothing changes. I get the same version output in the console. How do I upgrade node?
EDIT:
Here's the situation, I'm in a project folder with the following hierarchy:
node_modules seems to contain the react installation, since it has a react folder with a package.json file containing the version number 15.6.2.
I've tried both npm update --save react and npm update -g react. None worked. Same thing happens, and the same version number can be found in node_modules/react/package.json. I even tried to run npm install again before hosting with npm start. Any other suggestions?
Use npm update --save react to update to latest version.
For a specific version use npm update --save react#16.2.0.
React should not be installed globally but only for your project. If this is not the case use -g instead of --save
UPDATE
Okay my fault. Just use npm install --save react#16.2.0. This installs the new version.

Categories