0

I haven't touched node or coded in 3 years does anyone know how to fix this npm init

node:internal/modules/cjs/loader:922
  throw err;
  ^

Error: Cannot find module '../lib/cli.js'
Require stack:
- /usr/local/lib/node_modules/npm/bin/npm-cli.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:15)
    at Function.Module._load (node:internal/modules/cjs/loader:763:27)
    at Module.require (node:internal/modules/cjs/loader:991:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/npm/bin/npm-cli.js:2:1)
    at Module._compile (node:internal/modules/cjs/loader:1102:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1131:10)
    at Module.load (node:internal/modules/cjs/loader:967:32)
    at Function.Module._load (node:internal/modules/cjs/loader:807:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/usr/local/lib/node_modules/npm/bin/npm-cli.js' ]
}

i did

brew upgrade node

before this and tried

brew upgrade npm

and gives me

Warning: npm 15.3.0 already installed
mochi
  • 31
  • 3
  • 1
    https://stackoverflow.com/questions/29323982/error-cannot-find-module-lib-cli this may help – mostlyAsking7179 Dec 06 '20 at 00:07
  • can you post the output of `which node`? – Jatin Mehrotra Dec 06 '20 at 03:59
  • 1
    @JatinMehrotra i fixed it by renaming the node_modules folder and reinstalling it but now I have a black hole not sure how to clean up I deleted the renamed folder with ```rm -r foldername``` do you think that was enough? i tried to list out all the global packages after fixing npm but nothing was showing up – mochi Dec 06 '20 at 19:18
  • rm -r is enough to delete node_modules folders – Jatin Mehrotra Dec 07 '20 at 00:16
  • @JatinMehrotra I mean if it's enough to clean up the packages I wasn't able to uninstall with NPM – mochi Dec 07 '20 at 23:42

1 Answers1

1

I fix it by renaming the node_modules folder located in ''/usr/local/lib' and reinstalling node.js with the installer from nodejs.org which comes with npm

after that I ran rm -r noode_modules to remove the renamed copy of node_modules

not sure if deleting the folder was enough maybe I should have reinstalled all the old packages to overwrite whatever I had before and then removing it with npm uninstall to clean it up

mochi
  • 31
  • 3