为什么有时在Mac上npm install无法工作?

7

我创建了一个nodejs项目,当我运行命令npm install时,它会失败并显示一些错误。

这个项目在Ubuntu系统上运行良好,但是当我将代码克隆到Mac系统上并尝试运行npm install时,它会失败并显示一些错误。

我认为scrypt模块有问题,但我不确定原因。请帮助我,提前感谢。

操作系统:MAC
Node版本:10.15
Npm 版本:6.0

下面是错误信息:

WareWolf:mynodeapp$ npm install
> scrypt@6.0.3 preinstall /node_modules/scrypt
> node node-scrypt-preinstall.js

Error: Error: Command failed: ./configure
configure: error: /node_modules/scrypt/scrypt/scrypt-1.2.0':
configure: error: C compiler cannot create executables
See `config.log' for more details

> scrypt@6.0.3 install /node_modules/scrypt
> node-gyp rebuild

gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (/usr/local/Cellar/nvm/0.34.0/versions/node/v10.15.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)
gyp ERR! System Darwin 17.7.0
gyp ERR! command "/usr/local/Cellar/nvm/0.34.0/versions/node/v10.15.0/bin/node" "/usr/local/Cellar/nvm/0.34.0/versions/node/v10.15.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /node_modules/scrypt
gyp ERR! node -v v10.15.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! scrypt@6.0.3 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the scrypt@6.0.3 install script.

1
你是否看到了“查看 `config.log' 以获取更多详细信息”?它显示了什么?它正在尝试编译一个用C语言编写的模块。也许你需要更新Xcode(这只是猜测,我不是这方面的专家)。 - Patrick Hund
请发布 config.log。 - SanSolo
config.log在哪里? - Ishwar Chandra Tiwari
当我删除了 node_modules 文件时,npm install 就好用了,但我不知道问题是什么 => 我忘记在 .gitignore 文件中加入 node_modules 文件了。之前我使用的是 Ubuntu,当我在 Mac 系统中 git 克隆仓库,并尝试运行 npm install 时,它开始抛出错误。 - Ishwar Chandra Tiwari
2个回答

15

您需要删除package-lock.json.npmnode_modules文件夹。

必要步骤:

npm install npm@latest -g
npm cache clean — force
rm -rf ~/.npm
rm -rf node_modules
rm -f package-lock.json

在npm install .staging问题中,当您运行npm install时,它会创建node_modules文件夹,但所有模块都会进入名为.staging的子文件夹。


1
我在Linux机器上启动项目时遇到了同样的问题,希望能够从Mac上克隆并进行工作。
适用于我的解决方案是:
npm install --no-optional
更多信息:https://dev59.com/YFYN5IYBdhLWcg3wxqlv#47071650 另一种解决方法是删除package-lock.json文件。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接