How to uninstall nodejs from ubuntu20.04? - node.js

I was trying to create a react app and then I got an error like this:
A template was not provided. This is likely because you're using an outdated version of create-react-app.
Please note that global installs of create-react-app are no longer supported.
You can fix this by running npm uninstall -g create-react-app or yarn global remove create-react-app before using create-react-app again.
I thought my Node.js version was not compatible with the present react-app version so I decided to uninstall Node.js and install latest version. Then I used below commands to uninstall Node.js:
sudo npm uninstall create-react-app -g
npx clear-npx-cache
sudo apt-get remove nodejs
sudo apt-get purge nodejs
sudo apt-get autoremove
Even though I tried to uninstall, when I search for the Node.js version it's showing like this:
$ node -v
v14.4.0
Can anyone please tell me what's wrong and what I need to do to uninstall the present version and install the latest version?

Related

npm ERR! cb.apply is not a function

I am getting this error
npm ERR! cb.apply is not a function
in Linux while doing npm install although my npm version is 6.9.0. My node version is v12.18.3. How to resolve this issue?
Would be helpful if you shared if it's Windows or Linux, but the error seems to occur on Windows. Possible solution:
1. Go to C:\Users(your username)\AppData\Roaming
2. Delete the npm folder (possibly back it up) and if there is one npm cache folder.
3. Run `npm cache clear --force` (--force is now required to clean cache)
After that, npm install should work fine.
Mac/Macbook users
Since this question is fairly active and a top google result for this issue (I know the OP is using Linux), here is how to fix it on a Mac.
On a Mac you do not have the AppData\Roaming folder, so simply run npm root -g and then navigate to the hidden directory and delete the node_modules there. If using nvm you'll need to rerun nvm use x.x.x (where x.x.x is your version).
Solution for Windows:
In my case I didn't want to delete all the npm directory inside C:/users/me/AppData/Roaming/ because I had many global modules that already existed and installed.
What worked was inspired by #user14360499's answer:
go inside C:\Users\me\AppData\Roaming\npm\node_modules
delete the npm dir
npm install my project, and keep working as usually
Solution for ubuntu 18.04:
sudo apt-get remove nodejs
sudo apt-get remove npm
sudo rm /usr/local/bin/node
sudo rm /usr/local/bin/npm
sudo apt-get install nodejs
sudo apt-get install npm
Then try node and npm version:
node -v
npm -v
If it says there is no such node/npm after you already install, then:
sudo ln -s /usr/bin/node /usr/local/bin/node
sudo ln -s /usr/bin/npm /usr/local/bin/npm
Try this if the command works:
npm -v
node -v
In case when you want to update npm/node stable version:
sudo npm install n -g
sudo n stable
I had the same issue with Nodist. After changing my Node version, my npm version was actually incompatible with it. So if you're using Nodist, make sure to run nodist npm {scope} match after switching Node versions, where scope is either global, local or env.
For me, on Centos 7, it was about removing graceful-ts used locally by npx. First, I've had to open log file which was mentioned in the error message:
npm ERR! cb.apply is not a function
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-04-04T07_45_27_182Z-debug.log
In that log file there was this path:
verbose stack at /usr/local/lib/node_modules/npx/node_modules/npm/node_modules/graceful-fs/polyfills.js:287:18
So I removed whole graceful-fs directory and ran npx again. Everything worked.
rm -fR /usr/local/lib/node_modules/npx/node_modules/npm/node_modules/graceful-fs
Had the same error (macOS Big Sur) when i tried to use npx.
How i fixed it (using nvm)
when i run:
nvm ls
nvm ls output
Fix:
nvm alias default node
nvm install 'lts/*'
nvm install output
Ciao, this problem could be connected to graceful-fs package. You could try to reinstall it:
npm install graceful-fs --save-dev
In my case it was indeed the graceful-fs package. Running
npm i -g --force graceful-fs
fixed the issue. I also ran nodist npm {scope} match before but I'm unsure if it was neccessary.
Solution for Ubuntu 18.04=>
Visit 'usr/lib/node_modules'.
Delete 'n', 'npm','npm-clean','npm-install-peers'. That means delete all the node & npm related folders.
Install the npm again.
I have tried a lot of solutions from different posts and google pages and nothing worked for me.
I ended up cleaning all traces of node, nodejs, and npm. May need some manual force remove after the purge call. And then installed using nvm.
https://linuxize.com/post/how-to-install-node-js-on-ubuntu-20-04/#installing-nodejs-and-npm-using-nvm
And it resolved the issue for me. It got the nodejs v 15.4.0 and the compatible version of npm 7.0.15 ( before using apt-get it was installing npm 6.9.0)
On macOS BigSur, I had this problem when executing:
npx install-peerdeps --dev eslint-config-airbnb
To fix, I ran
brew update
after which I was prompted to run
brew upgrade
Running the two commands fixed the issue.
I had this problem while trying to run npx.
I found that nvm had been removed from the PATH.
I added it back to my .zshrc file and it worked.
In my case (Mac) it was because I had npx installed alongside n (alternative to nvm).
$ which npx
/usr/local/bin/npx
I removed this exectutable and now:
$ which npx
/Users/MY_USER/n/bin/npx
and it works now.
I was getting this error when running npx sb init. For some reason, the command worked localy but not in CI. I tried most of the solutions from here. But only the following worked.
I replaced npx sb init with yarn global add #storybook/cli && yarn exec sb init as suggested here: https://github.com/yarnpkg/yarn/issues/3937#issuecomment-751289438
(NVM, Node.js 14, Yarn 1)
if you are also getting this error:
1 warn npm npm does not support Node.js v16.2.0
that means that your npm version is not correct.
reinstall npm, try again.
It works for me.
Feb 2021 fix:
npm install
And then commit the changes to package-lock.json. That should update all your dependencies, thus fixing this issue.
More info: https://help.heroku.com/ZV7S7D6T/why-is-my-node-build-is-suddenly-displaying-npm-err-cb-apply-is-not-a-function (this happened to me on heroku)
For linux users:
uninstall NPM, to do it go to /usr/local/lib/node_modules and do:
sudo rm -r n npm npx
Once uninstalled, re-instal it:
npm install
Even after doing this, in a specific project when trying to install a specific npm package, you may get the following error:
bash: /usr/local/bin/npm: No such file or directory
If so, in the terminal just run:
hash -r
Now you can retry installation of your wanted npm package.
For me , the solution was to delete the node modules and bower components folder of the project.
for the mac OS remove the node version and reinstalling was work for me. I used n npm version manager.
On windows, using nvm, i just installed a newer nodejs version (before 14.17.0, now 14.18.2)
So many solutions just made me even more puzzled. I downloaded and installed the newest LTS NodeJS and it worked just fine.
https://nodejs.org/en/
I'm on a Mac, and had exactly the same issue. Deleting the node modules seemed a little overkill for me, so I ran npm update and it solved the issue! Please note I did not yet have any package.json or any modules on the repo I was working in.
Windows 10:
When calling npx create-react-app my-app, i got following error:
npm ERR! cb.apply is not a function
To fix it, i did the following:
Go to the folder you want to create the app in.
npm install create-react-app --save-dev
npx create-react-app my-app
The problem has occured when the node and npm packages are not latest.
For me the problem is resolved when I completely removed npm and node, and made a clean installation.
I am using ubuntu 22 lts
to remove node and npm completely I have followed this answer
Had this issue when creating a new react app using create-react-app.
I was using nvm, so I just updated it to the latest LTS version:
nvm install --lts
then switched to the newly installed lts version:
nvm use --lts
closed and reopened the terminal, reran create-react-app and the error was fixed!
Solution for ubuntu =>
Completely remove nodejs and npm from your system.
sudo apt-get remove nodejs
sudo apt-get remove npm
Install node from this reference (https://computingforgeeks.com/install-node-js-14-on-ubuntu-debian-linux/) - This will inturn install latest npm .
Had the same error was simply in the wrong folder -.- (not a typescript project)

How to upgrade angular-cli on Linux? Node.js V6.14.3 not supported by CLI v6

Whenever I enter ng in termial, it outputs
You are running version v6.14.3 of Node.js, which is not supported by
Angular CLI v6. The official Node.js version that is supported is 8.9
and greater.
Please visit https://nodejs.org/en/ to find instructions on how to
update Node.js
How to fix this issue?
This happens only in non root user account, works fine with root account
Your error message indicates, that your node version is not supported by angular.
So you should rather update node.
The current LTS is 8.11.3 which you can download here:
https://nodejs.org/en/
I've been using 'nvm' for this, it is a node version manager that allows you to install and switch between node versions very easily.
You can find it here:
https://github.com/creationix/nvm/blob/master/README.md
I was using nodejs v4.2.6 and npm v3.10.10
When I ran npm install -g #angular/cli, I think it tried to install latest version of angular-cli, hence I was getting this error.
You are running version v6.14.3 of Node.js, which is not supported by Angular CLI v6. The official Node.js version that is supported is 8.9 and greater.
Due to some reason, I didn't wanted to upgrade to latest node and npm packages, so I resolved it by npm install -g #angular/cli#1.1.1
Use n module from npm in order to upgrade node
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
To upgrade to latest version (and not current stable) version, you can use:
sudo n latest
To undo:
sudo apt-get install --reinstall nodejs-legacy # fix /usr/bin/node
sudo n rm 6.0.0 # replace number with version of Node that was installed
sudo npm uninstall -g n
Found in David Walsh blog

Having issues with updating Node.js

I am currently trying to update node to a current version. I have tried downloading and installing from the nodejs.org directly and I have also tried
brew upgrade node
and also
npm install -g n
npm cache clean -f
sudo n stable
npm update -g
Even after all that when I run "node -v", I still get my old version. It looks like when i run npm install -g n, it installs the old version instead of the new version.
Please help me update my node.

create-react-app not creating directory on Ubuntu 14.04

I've installed nodejs and npm using sudo apt-get. I've installed create-react-app using sudo npm install -g create-react-app but when I try to use create-react-app, it does absolutely nothing.
This
$ create-react-app my-app
did not create a directory.
I tried to make the directory and see if I could get create-react-app to populate it. This
$ mkdir my-app
$ create-react-app my-app
did absolutely nothing too.. The my-app directory stayed completely empty. It didn't even give an en error message.
How do I get create-react-app to work? To create and populate a directory as I think it should?
Update: when I installed create-react-app, I got the following warning.
npm WARN engine create-react-app#1.3.3: wanted: {"node":">=4"} (current: {"node":"v0.10.25","npm":"1.3.10"})
Did you try installing it globally?
i.e.
sudo npm install -g create-react-app
or
npm install -g create-react-app
create-react-app is a command line tool, so it needs to be installed globally in order for you to use it.
I figured it out. I needed to upgrade my version of nodejs using npm. I got the answer from this website. I skipped the first command that they recommend $ sudo npm cache clean -f, but probably should have done it. I used to following two commands.
$ sudo npm install -g n
$ sudo n stable
create-react-app now works fine.

install express with npm

I recently installed nodejs version 0.10.26 on ubuntu 64 bit. node -v and npm -v commands run fine and I can see the correct versions. When I do a $ sudo npm install -g express
the installation goes fine. But when I try to create a project with express as $ express myProject I get an error saying
The program 'express' is currently not installed. You can install it
by typing: sudo apt-get install node-express
Do I have to include some path in $PATH in order to run express? Please help.
With Express 4, the application generator was removed and is now available as 'express-generator.' So you need to npm install -g express-generator instead.
Enter the command in your terminal
npm install --save express

Resources