Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error cb.apply is not a function #2874

Open
allaura-dev opened this issue Jul 23, 2020 · 108 comments
Open

error cb.apply is not a function #2874

allaura-dev opened this issue Jul 23, 2020 · 108 comments

Comments

@allaura-dev
Copy link

  • Node.js Version:
    {
    npm: '4.6.1',
    ares: '1.16.0',
    brotli: '1.0.7',
    cldr: '37.0',
    icu: '67.1',
    llhttp: '2.0.4',
    modules: '83',
    napi: '6',
    nghttp2: '1.41.0',
    node: '14.6.0',
    openssl: '1.1.1g',
    tz: '2020a',
    unicode: '13.0',
    uv: '1.38.1',
    v8: '8.4.371.19-node.12',
    zlib: '1.2.11'
    }
  • OS: Windows 10
  • Scope (install, code, runtime, meta, other?): runtime

I can not do anything with my npm as I keep receiving "error cb.apply is not a function"

  • I have tried to clear the cache but it can not due to this error
  • I removed everything to do with does and the tools it downloads with it and reinstalled with windows up to date then rebooted but still receive the same error
    -i have tried npm doctor but failed due to this error
  • I have checked the path is correct for nodejs and node_modules
    How can i fix this issue?

Error chache information

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli 'C:\Program Files\nodejs\node.exe',
1 verbose cli 'C:\Users\allie\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js',
1 verbose cli 'install'
1 verbose cli ]
2 info using npm@4.6.1
3 info using node@v12.18.3
4 verbose config Skipping project config: C:\Users\allie/.npmrc. (matches userconfig)
5 silly install loadCurrentTree
6 silly install readLocalPackageData
7 verbose stack TypeError: cb.apply is not a function
7 verbose stack at C:\Users\allie\AppData\Roaming\npm\node_modules\npm\node_modules\graceful-fs\polyfills.js:287:18
7 verbose stack at FSReqCallback.oncomplete (fs.js:169:5)
8 verbose cwd C:\Users\allie
9 verbose Windows_NT 10.0.19041
10 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Users\allie\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js" "install"
11 verbose node v12.18.3
12 verbose npm v4.6.1
13 error cb.apply is not a function
14 verbose exit [ 1, true ]

@travisredington
Copy link

Yeah having the same issue with node 12.18.3 & 14.6.0

@allaura-dev
Copy link
Author

allaura-dev commented Jul 24, 2020

I solved it on both my computers. One needed more work on it.
Option 1:
Follow this directory
C:\Users(your username)\AppData\Roaming
Delete the npm folder and if there is one npm cache folder.
Run npm clean cache —force ( — force is now required to clean cache)
You should be good now if not do option 2.

Option 2:
Follow this directory
C:\Users(your username)\AppData\Roaming
Delete the npm folder and if there is one mom cache folder.
Run npm clean cache —force ( — force is now required to clean cache)
Make sure everything to do with Nodejs is deleted and uninstalled.
Reinstall Nodejs.
You should be good now.

@travisredington
Copy link

great, will try sometime soon, thanks!

@MattKehrls
Copy link

MattKehrls commented Jul 25, 2020

First Option worked great for me, thanks! (v.12.18.3)

@blackthought286
Copy link

worked. Thanks

@travisredington
Copy link

Yeah, option 1 worked for me as well! Thanks! ( using v14.6.0 )

@aldanin
Copy link

aldanin commented Jul 25, 2020

First option worked for me.
Thanks a bunch!

@shuiche-it
Copy link

mac how to do?

@Ivo-Balbaert
Copy link

Thank you very much!!

@AHassanSOS
Copy link

This error is new. It happens if I try to install npm twice in the row.

@kulor
Copy link

kulor commented Jul 29, 2020

I found resolve in downgrading to Node 12.18.2 as the graceful-fs that was being used was hard linked by an older dependency of mine. For the lazy (Linux):

NODE_VERSION=12.18.2
curl -sSL "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" | sudo tar --strip-components=2 -xJ -C /usr/local/bin/ node-v$NODE_VERSION-linux-x64/bin/node

@ridhi-mago
Copy link

I solved it on both my computers. One needed more work on it.
Option 1:
Follow this directory
C:\Users(your username)\AppData\Roaming
Delete the npm folder and if there is one mom cache folder.
Run npm clean cache —force ( — force is now required to clean cache)
You should be good now if not do option 2.

Option 2:
Follow this directory
C:\Users(your username)\AppData\Roaming
Delete the npm folder and if there is one mom cache folder.
Run npm clean cache —force ( — force is now required to clean cache)
Make sure everything to do with Nodejs is deleted and uninstalled.
Reinstall Nodejs.
You should be good now.

First option worked!! Thanks!

@HarelM
Copy link

HarelM commented Aug 1, 2020

Can the solution provided by @allaura-dev added to nodejs installer in case of major version upgrade?
I updated nodejs today and ran into the same issue just to find out someone already found a solution... :-(

@yasarui
Copy link

yasarui commented Aug 2, 2020

First option worked for me. Thanks a lot

@lumosmind
Copy link

First option worked. Thanks a lot

@Naz786
Copy link

Naz786 commented Aug 6, 2020

Guys if you are trying to follow the answer above and you cannot access the 'C:\Users(your username)\AppData\Roaming' folder, then go to 'this PC' in file explorer, search 'npm', you will see folders 'npm' or 'npm-cache' which are inside '...AppData\Roaming' folders. Delete these by accessing the path to '...\AppData\Roaming'.

@allaura-dev
Copy link
Author

Can the solution provided by @allaura-dev added to nodejs installer in case of major version upgrade?

I updated nodejs today and ran into the same issue just to find out someone already found a solution... :-(

I agree. I was working on a new project and the same thing happened.

@teknorix1
Copy link

I solved it on both my computers. One needed more work on it.
Option 1:
Follow this directory
C:\Users(your username)\AppData\Roaming
Delete the npm folder and if there is one mom cache folder.
Run npm clean cache —force ( — force is now required to clean cache)
You should be good now if not do option 2.

Option 2:
Follow this directory
C:\Users(your username)\AppData\Roaming
Delete the npm folder and if there is one mom cache folder.
Run npm clean cache —force ( — force is now required to clean cache)
Make sure everything to do with Nodejs is deleted and uninstalled.
Reinstall Nodejs.
You should be good now.

You saved me, Thanks

@gigamonkey
Copy link

mac how to do?

It seems that you can use npm root -g to find the directory which is not AppData\Roaming on a mac. Though in my case it turned out I had an old ~/node_modules/ lying around causing problems. When I deleted it this problem went away.

@blackraspberryyy
Copy link

For me, it worked when I reinstalled graceful-fs by running npm install graceful-fs --save-dev as suggested by Giovanni Esposito here: https://stackoverflow.com/questions/63054545/all-my-react-native-projects-shows-error-typeerror-cb-apply-is-not-a-function/63054816#63054816

@SrikanthCM
Copy link

I solved it on both my computers. One needed more work on it.
Option 1:
Follow this directory
C:\Users(your username)\AppData\Roaming
Delete the npm folder and if there is one npm cache folder.
Run npm clean cache —force ( — force is now required to clean cache)
You should be good now if not do option 2.

Option 2:
Follow this directory
C:\Users(your username)\AppData\Roaming
Delete the npm folder and if there is one mom cache folder.
Run npm clean cache —force ( — force is now required to clean cache)
Make sure everything to do with Nodejs is deleted and uninstalled.
Reinstall Nodejs.
You should be good now.

Thank you very much option 1 helped a 2 hour problem

@xaviergmail
Copy link

I found resolve in downgrading to Node 12.18.2 as the graceful-fs that was being used was hard linked by an older dependency of mine. For the lazy (Linux):

NODE_VERSION=12.18.2
curl -sSL "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" | sudo tar --strip-components=2 -xJ -C /usr/local/bin/ node-v$NODE_VERSION-linux-x64/bin/node

For me, this seemed to be the only solution on WSL. WSL2 / debian sid

@detj
Copy link

detj commented Aug 19, 2020

Getting this exact error on macOS 10.15.6

It seems that you can use npm root -g to find the directory which is not AppData\Roaming on a mac. Though in my case it turned out I had an old ~/node_modules/ lying around causing problems. When I deleted it this problem went away.

I didn't have any duplicate node_modules at npm -g root. I deleted all global packages except npm. But this problem still exists.

I faced this while trying to serve a static website

$ ls
public
$ npx serve public/
npm ERR! cb.apply is not a function

@Pzixel
Copy link

Pzixel commented May 3, 2021

Facing this issue right now on freshly installed Node 16.0. Nothing listed above helped so far :(

@YATACOBLAS
Copy link

Great, Option 1 Work for me

@matronator
Copy link

I found resolve in downgrading to Node 12.18.2 as the graceful-fs that was being used was hard linked by an older dependency of mine. For the lazy (Linux):

NODE_VERSION=12.18.2
curl -sSL "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" | sudo tar --strip-components=2 -xJ -C /usr/local/bin/ node-v$NODE_VERSION-linux-x64/bin/node

Or if you use nvm for managing different node versions, you can do this instead:

nvm install 12.18.2
nvm use 12.18.2

This fixed it as well (on macOS).

If you don't have nvm installed I highly recommend getting it, because these sorts of issues pop up quite often and with nvm you can easily change your node versions without overwriting your current installation. Instructions how to install: https://nodejs.org/en/download/package-manager/#nvm

@youssefbenfarhat
Copy link

Still not working with v14.16.1

@charithar
Copy link

Option 1 worked nicely!

@RomeshKTripathi
Copy link

I faced this exact problem first time and I tried most of the methods available here at last

Step 1: Deleted npm folder from :C:\Users'user-name'\AppData\Roaming
Step 2: Run command: npm clean cache -force
Step 3: Run command: npm install create-react-app -g
Step 4: Move in your target forder and Run command: npx create-react-app appName

I hope this will solve your issue 99.9%.

@inceabdullah
Copy link

I fixed it

  1. by upgrading npm first:

npm install -g npm@latest --force

  1. remove npx

npm uninstall -g npx

  1. re-install it with the arg --force

npm install --force -g npx@latest

@gangsthub
Copy link

What worked for me: (using pnpm to upgrade the npm version!)

pnpm add -g npm@6

Then npm was updated successfully to its latest minor version inside v6.

This whole issue started when I was using nvm to switch versions here and there...

@AreyXo
Copy link

AreyXo commented Oct 22, 2021

I fixed it

  1. by upgrading npm first:

npm install -g npm@latest --force

  1. remove npx

npm uninstall -g npx

  1. re-install it with the arg --force

npm install --force -g npx@latest

this worked!

@tjbortz1s
Copy link

So, if you try this and it doesn't work, it may be that the app was installed to a weird place.

My computer has all of its app data and other documents redirected to a network share, but at some point the npm installer installed npm to a folder on the C drive with the same name as the network share.

Look for that if you're in a similar boat.

@markmackend
Copy link

I found resolve in downgrading to Node 12.18.2 as the graceful-fs that was being used was hard linked by an older dependency of mine. For the lazy (Linux):

NODE_VERSION=12.18.2
curl -sSL "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" | sudo tar --strip-components=2 -xJ -C /usr/local/bin/ node-v$NODE_VERSION-linux-x64/bin/node

This worked for me! Thanks!

@Ahmmad86
Copy link

I solved it on both my computers. One needed more work on it. Option 1: Follow this directory C:\Users(your username)\AppData\Roaming Delete the npm folder and if there is one npm cache folder. Run npm clean cache —force ( — force is now required to clean cache) You should be good now if not do option 2.

Option 2: Follow this directory C:\Users(your username)\AppData\Roaming Delete the npm folder and if there is one mom cache folder. Run npm clean cache —force ( — force is now required to clean cache) Make sure everything to do with Nodejs is deleted and uninstalled. Reinstall Nodejs. You should be good now.

the same thing happen with me , am used ur solve and all thing gets right

@JEF2050
Copy link

JEF2050 commented Nov 21, 2021

thanks!!, the firts option worked to me...:)

@RyanLiu0235
Copy link

Listen to me, download and install the newest LTS version NodeJS, and the world turns out just fine.

@mycoberago
Copy link

This worked for me and I hope it's helpful...

Tried everything suggested but none worked.

I noticed that since I am using NVM, everything points to /Users/{username}/.nvm/...etc when checking for node, npm and npx versions. However, when executing npx create-react-app command, the error points to /Users/{username}/node_modules/npm/node_modules/graceful-fs/polyfills.js:287:18

It's using the correct node version through NVM but it's reverting to using the wrong node_modules folder as if it's the default. I deleted the node_modules folder and it all worked perfect.

@yangqiang1
Copy link

我试过了所有方法还是不行

@yangqiang1
Copy link

我试过了所有方法还是不行

finally,I did it by nvm using old version eg 14.18.2, it is unuseful by using node(the latest version).

@Fahad16301139
Copy link

thanks!first option worked for me!!

@fernenfern
Copy link

I solved it on both my computers. One needed more work on it. Option 1: Follow this directory C:\Users(your username)\AppData\Roaming Delete the npm folder and if there is one npm cache folder. Run npm clean cache —force ( — force is now required to clean cache) You should be good now if not do option 2.

Option 2: Follow this directory C:\Users(your username)\AppData\Roaming Delete the npm folder and if there is one mom cache folder. Run npm clean cache —force ( — force is now required to clean cache) Make sure everything to do with Nodejs is deleted and uninstalled. Reinstall Nodejs. You should be good now.

Thanks ! Worked for me .Thank u very much

@bobcorp99
Copy link

I had the same problem, tried it out, and It works, THANK YOU!

@arashi-dev
Copy link

Another Solution

I don't know how it worked but I deleted folder C:\Users\[username]\AppData\Local\Yarn and repaired the nodejs through the exe file and it got fixed. now I can use the latest version of npm.

@erg
Copy link

erg commented Jun 7, 2023

for macos:

which npx
/Users/erg/.nvm/versions/node/v18.2.0/bin/npx

nuke it all:
rm -rf ~/.nvm/versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests