1

Mac OS Catalina (10.15.7)

I did a brew install npm and now am trying to run an app locally, and I get this. I don't have a node_modules directory that a lot of the posted solutions recommend to be deleted. I also removed my package-lock.json file to no avail.

Note this did not happen on an AWS-linux instance.

$ npm install
node:internal/modules/cjs/loader:928
  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:925:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Module.require (node:internal/modules/cjs/loader:997: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:1108:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:973:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813: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' ]
}

What to do? Thanks.

Chris F
  • 14,337
  • 30
  • 94
  • 192
  • Maybe tangential, but I'm curious as to why you're seeking to install `npm` via Homebrew when there are [official macOS binaries available](https://nodejs.org/en/download/)? – esqew Jan 09 '21 at 21:07
  • Does this answer your question? [Error: Cannot find module '../lib/cli'](https://stackoverflow.com/questions/29323982/error-cannot-find-module-lib-cli) – Or Assayag Jan 09 '21 at 21:07
  • @esqew, yes installing it via the package manager (after uninstalling it in brew) solved my issue. You can post that as an answer and I'll accept it. thanks. – Chris F Jan 09 '21 at 21:17
  • @OrAssayag, no. running any `npm install ...`, which that link suggests, causes the issue. – Chris F Jan 09 '21 at 21:18
  • One other possibility is to install via `n`, which can be installed with `n-install` without a pre-existing Node/npm installation. That also gives you version management so you don't have to manually update. – Zac Anger Jan 09 '21 at 21:24

1 Answers1

0

Anecdotally, I've seen a lot of weird (and otherwise hard-to-diagnose) issues stem from trying to install npm and other Node components via Homebrew. I find that tutorials/guides/articles recommending otherwise are quite outdated.

I generally recommend installing Node and npm only via the official installers or with a package manager set to download from official sources, unless you have a really good reason to do otherwise.

esqew
  • 42,425
  • 27
  • 92
  • 132