Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
438 views
in Technique[技术] by (71.8m points)

node.js - npm install fails on Mac OS

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.

question from:https://stackoverflow.com/questions/65647582/npm-install-fails-on-mac-os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...