help icon indicating copy to clipboard operation
help copied to clipboard

error cb.apply is not a function

Open allaura-dev opened this issue 6 years ago • 112 comments

  • 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 [email protected] 3 info using [email protected] 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 ]

allaura-dev avatar Jul 23 '20 15:07 allaura-dev

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'.

I actually had to do this hard search to get the npm and npm-cache files removed. Now it's working. Thank you!

russhuq avatar Mar 14 '21 02:03 russhuq

On Win 10, to get past this bug I had to uninstall and reinstall node in addition to removing the npm, npm-cache and node_modules folders mentioned.
The npm clean cache —force did not even run properly.

corymalcolmtaylor avatar Mar 15 '21 08:03 corymalcolmtaylor

I got the same issue on macOS. Here is my solution. Besides the error message above, there are other tips: npm ERR! A complete log of this run can be found in: npm ERR! /Users/xxx/.npm/_logs/2020-10-20T07_41_00_394Z-debug.log Open the file of xxx-debug.log: /// verbose cli '/usr/local/Cellar/node/14.12.0/bin/node', verbose cli '/Users/xxx/node_modules/.bin/npm', <-------!!! wrong verbose cli 'install',6 verbose cli '--loglevel', verbose cli 'error',6 verbose cli '@vue/cli-plugin-babel@~4.5.0', verbose cli '@vue/cli-plugin-eslint@~4.5.0', verbose cli '@vue/cli-service@~4.5.0', verbose cli '--save-dev'6 verbose cli ] info using [email protected] <-------!!! wrong info using [email protected] /// I found the npm version and path are wrong. I open the path of the npm of log file. cd /Users/xxx/node_modules/.bin/ then i run the command of ls -al. /// lrwxr-xr-x npm -> ../npm/bin/npm-cli.js lrwxr-xr-x npx -> ../npm/bin/npx-cli.js ///The links above point to wrong paths. The correct paths are : lrwxr-xr-x npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js lrwxr-xr-x npx -> /usr/local/lib/node_modules/npm/bin/npm-cli.js After recorrecting these links. vue works well.

Oh holy cow, this is exactly what I needed to fix the issue. Wow, thank you!

ghost avatar Mar 19 '21 14:03 ghost

I deleted npm and npm-cache as suggested, but the clean command which worked for me was "npm cache clean --force"

robertmazzo avatar Mar 25 '21 21:03 robertmazzo

Just wanna add the after struggling with this problem for hours, on my react-native project I only managed to fix it thanks to this stack overflow answer: https://stackoverflow.com/questions/63214997/typeerror-cb-apply-is-not-a-function

Add this to your package.json:

"resolutions": {
    "graceful-fs": "4.2.4"
  },

then run yarn or npm run install. Hope it helps someone else struggling considering this thread if one of the first showing up when googling while the stackoverflow answer is a bit more hidden.

gbalduzzi avatar Mar 26 '21 11:03 gbalduzzi

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 ! the second option worked !

myms-soft avatar Apr 05 '21 13:04 myms-soft

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

Pzixel avatar May 03 '21 23:05 Pzixel

Great, Option 1 Work for me

YATACOBLAS avatar May 05 '21 18:05 YATACOBLAS

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

matronator avatar May 10 '21 12:05 matronator

Still not working with v14.16.1

youssefbenfarhat avatar May 10 '21 12:05 youssefbenfarhat

Option 1 worked nicely!

charithar avatar May 19 '21 18:05 charithar

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

inceabdullah avatar Aug 11 '21 13:08 inceabdullah

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...

paulmelero avatar Aug 27 '21 04:08 paulmelero

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!

AreyXo avatar Oct 22 '21 07:10 AreyXo

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.

tjbortz1s avatar Oct 29 '21 15:10 tjbortz1s

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!

markmackend avatar Oct 30 '21 00:10 markmackend

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

Ahmmad86 avatar Nov 11 '21 21:11 Ahmmad86

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

JEF2050 avatar Nov 21 '21 15:11 JEF2050

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

RyanLiu0235 avatar Dec 10 '21 09:12 RyanLiu0235

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.

mycob avatar Feb 21 '22 12:02 mycob