I met some problems about installing yarn with npm/nvm - node.js

After i installed nvm, I ran
nvm install 8.15.0
then I have node#v8.15.0 installed.
But when I ran
nvm use 8.15.0
npm install -g yarn
I got this message in my terminal:
/Users/bellemere/.nvm/versions/node/v8.9.4/bin/yarn -> /Users/bellemere/.nvm/versions/node/v8.9.4/lib/node_modules/yarn/bin/yarn.js
/Users/bellemere/.nvm/versions/node/v8.9.4/bin/yarnpkg -> /Users/bellemere/.nvm/versions/node/v8.9.4/lib/node_modules/yarn/bin/yarn.js
+ yarn#1.15.2
updated 1 package in 2s
Shouldn't yarn be installed under v8.15.0?
Does anyone meet this problem before?

I checked the terminal log and find there was a config file called '~/.npmrc'.
I just deleted the content in it and now everything is OK.

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)

spawn yarnpkg ENOENT

This happens when I run expo install expo-permissions
It explicitly returns me
Installing 1 SDK 35.0.0 compatible native module using Yarn.
yarn add expo-permissions#~7.0.0
spawn yarnpkg ENOENT
Set EXPO_DEBUG=true in your env to view the stack trace.
Which is strange because I don't normally use Yarn. I use NPM to install dependencies.
I know this error has to do with my files or some path not being configured correctly. What I don't know is which path it is that I have to change and how to do so.
Please let me know if there is any other relevant info that I should add here.
I had the same problem as you my solution and you perform the installation of yarn via npm:
npm i -g yarn
I believe this error is caused because he cannot find the symbolic link for yarnpkg. When executing this command, yarn will be updated and linked.
You can just pass the flag --npm after the command.
expo install [package-name] --npm
Best solution for this would be using --npm flag
Example:
expo install pkname --npm,
expo update --npm,
expo upgrade --npm,
This is happened because you haven't executed yarn install or yarn command.
Yes, I tried many ways and finally, I found the solution.
The issue was different yarn package version.
So first of all, you need to upgrade yarn version lastest.
open terminal and type the following.
npm install --global yarn
expo update
Hope this solve your issue.
I had a similar problem. You should install yarn in your system, since that's what Expo CLI is trying to execute to install packages. For me my issue was that I did had yarn but I had an old version. I had to update my yarn version to 1.19.0. If you install this version it should work correctly.
I recommend using yvm to install and manage different versions of yarn. After you install yvm it is as easy to install yarn as yvm install <version>, so in this case you would do yvm install 1.19.0. And if you ever have to change versions because another project doesn't work with 1.19.0 (sometimes it happens) you can just install another version and change between versions by doing yvm use <version>.
Hope this helps!
This worked for me:
Latest Yarn Installation (from here)
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update && sudo apt install yarn
sudo apt update && sudo apt install --no-install-recommends yarn
Add this to your profile: export PATH="$PATH:/opt/yarn-[version]/bin" (the path may vary depending on where you extracted Yarn to)
In the terminal, log in and log out for the changes to take effect
yarn --version checks if the version is latest (1.0+).
Then expo update <version> (ex: 36.0.0)
Concideration:
Do not forget to check if you give attention to similar warning: "warning package-lock.json found. Your project contains lock files generated by tools other than Yarn."
"spawn yarnpkg ENOENT" usually indicates that the system cannot find the "yarnpkg" command.
npm i -g corepack
This worked for me.
For nextjs you can try this as I found out that I am npx not yarn same as how I start npx expo start
npx expo update

error eslint#5.6.0: The engine "node" is incompatible with this module. when trying to create-react-app

I am trying to create a React App and I am getting the following error in my console.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
yarn add v1.10.1
info No lockfile found.
[1/4] 🔍 Resolving packages...
warning react-scripts > eslint > file-entry-cache > flat-cache > circular- json#0.3.3: CircularJSON is in maintenance only, flatted is its successor.
[2/4] 🚚 Fetching packages...
error eslint#5.6.0: The engine "node" is incompatible with this module. Expected version "^6.14.0 || ^8.10.0 || >=9.10.0". Got "9.5.0"
error Found incompatible module
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
Aborting installation.
yarnpkg add --exact react react-dom react-scripts --cwd /Volumes/server2/Desktop/JavaScript/birdcage has failed.
Deleting generated file... package.json
Deleting birdcage / from /Volumes/server2/Desktop/JavaScript
Done.
I have tried brew upgrade node but that didn't seem to work. Any ideas on how this can be fixed would be greatly appreciated.
One of the temporally fix is to run yarn install --ignore-engines
I was facing the same issue, try to add "--use-npm" at the end of create react app commend.
create-react-app appname --use-npm
I had the same problem, simply doing this solved the problem:
npm install node#latest
Try to uninstall yarn and install it via npm.
npm i create-react-app -g
create-react-app yourappname
Make sure that node is installed!
I had the same problem, try it:
yarn config set ignore-engines true
I re-installed node and updated xcode developer tools. Also, re-installed React on that computer which is running Mojave.
Assuming nvm is installed, use it to see which version of node you're using, then use it to change to a later version.
you can change the version with nvm use <version> and then try again
In my Ubuntu 18.04 had a native version from the OS installed that not listed by NVM.
I removed it and then I ran:
Firstly run, nvm install 14.5.0
then run, nvm use 14.5.0
And the installation completed properly.
i had same issue when i was adding router plugin to vue-cli with npx and yarn as well..
In pyhton virtual environment i have updated node version from 8.x.x to 16.x.x and used command nvm use 16.x.x but still problem persists .. i was actually executing command as root .. so nvm is using node version as 8.x.x only ..
after long time i realised executing command with sudo was the issue and then executed as a normal user...
this solution worked for me !!!
As the warning said, I updated node via nvm to the version required. For me having the latest node lts version was enough.
nvm install "lts/*" --reinstall-packages-from="$(nvm current)"
But even after upgrading node, yarn still gave the error.
The problem was npm was still executed from the old .bin path of previous node version. nvm also installs latest version of npm in respective local .bin folder for the node version installed.
I used the following commands then,
nvm install-latest-npm: Attempt to upgrade to the latest working npm on the current node version
nvm install --latest-npm: After installing, attempt to upgrade to the latest working npm on the given node version
After this, it worked properly.
Reference:
How can I change the version of npm using nvm?

How Do I Uninstall Yarn

How can I uninstall yarn? I've used it for a react-native project and now whenever I move the code out of index.ios.js or index.android.js it throws an error so I'd like to just use npm but whenever I initialize a react-native project it defaults to yarn. I tried npm uninstall yarn but that didn't work. Thanks.
Depends on how you installed it:
brew: brew uninstall yarn
tarball: rm -rf "$HOME/.yarn"
npm: npm uninstall -g yarn
ubuntu: sudo apt-get remove yarn && sudo apt-get purge yarn
centos: yum remove yarn
windows: choco uninstall yarn (or go to control panel > add/remove programs and uninstall it from there)
Try this, it works well on macOS:
$ brew uninstall --force yarn
$ npm uninstall -g yarn
$ yarn -v
v0.24.5 (or your current version)
$ which yarn
/usr/local/bin/yarn
$ rm -rf /usr/local/bin/yarn
$ rm -rf /usr/local/bin/yarnpkg
$ which yarn
yarn not found
$ brew install yarn
$ brew link yarn
$ yarn -v
v1.17.3 (latest version)
Or you could install it as recommended on the website (https://classic.yarnpkg.com/lang/en/docs/install/#mac-stable) through npm using:
$ npm install --global yarn
Didn't see the answer that worked for me, so here it is: On my OSX system I found yarn at ~/.yarn/bin/yarn. rm -rf ~/.yarn took care of it.
on windows: Go to "Add or remove programs" in control panel (or open the start menu and search for "remove program")
https://github.com/yarnpkg/yarn/issues/3331
If you are using corepack and previously ran the command corepack enable, then you can uninstall yarn via the following command:
corepack disable yarn
If you installed with brew, try brew uninstall yarn at terminal prompt. Also remember to remove yarn path info in your .bash_profile.
I'm using macOS. I had a few versions of yarn installed with Homebrew, which I uninstalled with brew uninstall --force yarn. I then installed the latest version 1.7.0 of Yarn using Homebrew brew install yarn
But still when I ran which yarn, it returned /Users/Me/.yarn/bin/yarn, and yarn --version returned 0.24.6. There was no mention of Yarn in ~/.bash_profile, but my ~/.bashrc file contained the line export PATH="$HOME/.yarn/bin:$PATH" indicating that I must have previously installed Yarn globally, but I only wanted to use the latest version that I just installed with Homebrew.
So I uninstalled Yarn globally by running npm uninstall -g yarn; rm -rf ~/.yarn, then editing the file ~/.bashrc by changing the line to export PATH="/usr/local/bin/yarn:$PATH" and running source ~/.bashrc to update the PATH in the terminal session. Then when I ran which yarn it returned /usr/local/bin/yarn, and when I ran yarn --version it returned
1.7.0
In case you installed yarn globally like this
$ sudo npm install -g yarn
Just run this in terminal
$ sudo npm uninstall -g yarn
Tested now on my local machine running Ubuntu. Works perfect!
I tried the Homebrew and tarball points from the post by sospedra. It wasn't enough.
I found yarn installed in: ~/.config/yarn/global/node_modules/yarn
I ran yarn global remove yarn. Restarted terminal and it was gone.
Originally, what brought me here was yarn reverting to an older version, but I didn't know why, and attempts to uninstall or upgrade failed.
When I would checkout an older branch of a certain project the version of yarn being used would change from 1.9.4 to 0.19.1.
Even after taking steps to remove yarn, it remained, and at 0.19.1.
What I've done on my side:
Went to the /usr/local/lib/node_modules, and deleted the yarn folder inside it.
I couldn't uninstall yarn on windows and I tried every single answer here, but every time I ran yarn -v, the command worked. But then I realized that there is another thing that can affect this.
If you on windows (not sure if this also happens in mac) and using nvm, one problem that can happen is that you have installed nvm without uninstalling npm, and the working yarn command is from your old yarn version from the old npm.
So what you need to do is follow this step from the nvm docs
You should also delete the existing npm install location (e.g. "C:\Users<user>\AppData\Roaming\npm"), so that the nvm install location will be correctly used instead. Backup the global npmrc config (e.g. C:\Users<user>\AppData\Roaming\npm\etc\npmrc), if you have some important settings there, or copy the settings to the user config C:\Users<user>.npmrc.
And to confirm that you problem is with the old npm, you will probably see the yarn.cmd file inside the C:\Users\<user>\AppData\Roaming\npm folder.
npm uninstall yarn removes the yarn packages that are installed via npm but what yarn does underneath the hood is, it installs a software named yarn in your PC. If you have installed in Windows, Go to add or remove programs and then search for yarn and uninstall it then you are good to go.
For Windows User:
Just use the installer file(i.e yarn-1.22.4.msi in my case) to uninstall yarn.
Once you open the installer you will get three options, i.e to install, repair and uninstall yarn from your machine.
Select uninstall and it will remove all the yarn files from your pc.
For windows user:
npm uninstall -g yarn
For Mac user:
$ npm uninstall -g yarn
It will completely be remove yarn for your system.
If on your system, Yarn is provided from Node.js, through corepack, then, you can choose which version of Yarn you want to use, with the following:
corepack prepare yarn#x.y.z --activate
–as per https://nodejs.org/api/corepack.html#upgrading-the-global-versions
On my Mac neither of these regular methods to uninstall Yarn worked:
brew: brew uninstall yarn
npm: npm uninstall -g yarn
Instead I removed it manually by typing rm -rf ~/.yarn (thanks user elthrasher) and deleting the two symbol links yarn and yarnpkg from usr/local/bin.
Afterwards brew install yarn gave me the latest version of Yarn.
Background: The fact that I had a very outdated version of Yarn installed gave me utterly incomprehensible errors while trying to install additional modules to a project set up with Vue CLI Service and Vue UI, which apparently uses Yarn 'under the hood'. I generally use NPM so it took me a while to figure out the cause for my trouble. Naturally googling error messages produced by such module incompatibilities presented no clues. With Yarn updated everything works just perfectly now.
If you are still getting errors after deleting ~/.yarn about files not being found, don't forget to delete the yarn rc file:
rm ~/.yarnrc.yml
This is how to uninstall yarn completely for Mac Users
sudo npm uninstall -g yarn
In the case of windows, after executing npm uninstall -g yarn, still if yarn did not uninstalled, then go to "C:\Users\username\AppData\Local" and remove the yarn folder.
Close the cmd and reopen the cmd and execute yarn . it will give you message 'yarn' is not recognized as an internal or external command, operable program or batch file.
Try "npm uninstall -g yarnpkg"(global) or "npm uninstall yarnpkg"(local) if you installed it with npm.
That's what worked for me.
If that still doesn't work and you installed it with npm, do "npm list -g" to check if you installed it globally or "npm list" if you installed it locally. Hope that helps anyone having this problem. :D
EDIT: Found something if you installed yarn with .msi executable you have to install it the normal windows way.
I had to manually remove(delete) the Yarn folder from drive and then run npm uninstall -g yarn again to reinstall it. It worked for me.
For Windows:
I need to do these steps to completely remove the yarn from the system.
Go to add or remove programs and then search for yarn and uninstall it(if you installed it with the .msi)
npm uninstall -g yarn (if you installed with npm)
Remove any existing yarn folders from your Program Files (x86) (Program Files (x86)\Yarn).
Also need to delete your Appdata\local\yarn folder ( type %LOCALAPPDATA% in the run dialog box (win+R), it opens a local folder and there you'll find the yarn folder to delete)
Finally,check your user directory and remove all .yarn folder, .yarn.lock file, .yarnrc etc ( from C:\Users\<user>\)
remove yarn
# macOS & brew
$ brew uninstall yarn
remove npm package
# yarn global remove
$ sudo yarn global remove #tarojs/cli
# yarn global add
$ sudo yarn global add #tarojs/cli
refs:
https://classic.yarnpkg.com/en/docs/cli/global/
https://classic.yarnpkg.com/en/docs/cli/remove/
It really works when I'm still getting errors after deleting ~/.yarn
rm ~/.yarnrc.yml
We must delete .yarnrc.yml or .yarnrc file
I found the other answers a bit inadequate since I wanted to "completely" remove yarn from my Mac (M1). I found this worked:
First remove it how you installed it i.e. same as this.
Remove the cache. For example on my Mac I ran:
rm -rf ~/Library/Caches/Yarn
Remove the global node_modules cache of Yarn:
rm -rf ~/.config/yarn
yarn cache clean did not help get rid of the above which tool significant space.
Remove any other Yarn-related config files:
rm -rf ~/.yarn
rm ~/.yarnrc
ng set --global packageManager=npm OR ng set --global packageManager=yarn
Just copy this command and your problem will be fixed.
npm uninstall yarn

npm still installing packages to '/usr/local/Cellar/node/...' even though I've uninstalled Homebrew's version of node

It's been a long night. Originally I had node installed from the package on https://nodejs.org/. However, for some reason (I can't remember why now!), I decided to try uninstalling this and then installing node through Homebrew.
Everything seemed to go fine. I then ran the following:
$ npm install grunt -g
$ npm install grunt-cli -g
But then when I tried running any of my Grunt tasks I get the following:
$ cd /some/project/that/used/grunt
$ grunt
-bash: grunt: command not found
I tried uninstalling the Homebrew version of node:
$ brew uninstall node
I then installed the nodejs.org package again. However when I try to install an npm package it ends up back in the /usr/local/Cellar/node/... directory:
$ sudo npm install grunt -g
Password:
grunt#0.4.5 /usr/local/Cellar/node/0.12.2_1/libexec/npm/lib/node_modules/grunt
├── which#1.0.9
...
I also found https://github.com/Homebrew/homebrew/issues/22408 and tried the symlink:
$ ln -sf /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm
No luck. How can I get npm to stop installing packages in /usr/local/Cellar/... and get Grunt running again? Thank you!
This seemed to work. I found the following in /usr/local/lib/node_modules/npm/npmrc:
prefix=/usr/local/Cellar/node/0.12.2_1/libexec/npm
I removed this line and re-installed the grunt and grunt-cli packages. It works now.

Resources