我使用自制(Mojave)安装节点,之后php停止工作,如果我尝试运行php -v,我会得到这个错误:

php -v
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib
  Referenced from: /usr/local/bin/php
  Reason: image not found

我尝试卸载node和icu4c,但问题仍然存在


当前回答

我的问题:

# npm install -g canvas

dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.64.dylib
  Referenced from: /usr/local/opt/node@8/bin/node
  Reason: image not found

现在20210118,经过多次尝试:

...
brew reinstall https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/icu4c.rb
brew upgrade npm
brew install node
brew uninstall --ignore-dependencies node@8 icu4c
brew install icu4c
...

最终解决方案为:

重新安装NPM

其他回答

对我来说,解决办法是:

brew reinstall icu4c

Then

gem uninstall charlock_holmes
gem install charlock_holmes

我把macOS升级到10.13.6版本后也遇到了同样的问题。我不能运行composer和php命令。在研究了一段时间并尝试了网上发布的各种解决方案后,使用homebrew重新安装php成功了。

酿造重新安装php@7.1

3月14日根据Ryan的评论添加的

通过运行PHP -v获取当前使用的版本,并获得正确的公式(可以在这里找到:https://formulae.brew.sh/formula/php)来替换上面命令中的@7.1。

这为我解决了问题:

brew upgrade node

运行npm version,如果你看到同样的错误,升级npm。

酿造升级npm。

==> Upgrading 1 outdated package, with result:
npm 8.1.2 -> 10.3.0
==> Upgrading npm
==> Installing dependencies for node: icu4c
==> Installing node dependency: icu4c

学分

实际上,我很惊讶这个解决方案还没有提出,我觉得这是最简单的解决方案。

去GitHub,找到与你需要的icu4c版本匹配的brewfile版本,并获得文件的原始版本(按照上面的链接,然后单击“查看文件然后原始”)。

然后让brew从那个url重新安装。

例如,版本62.1:

brew reinstall https://raw.githubusercontent.com/Homebrew/homebrew-core/575eb4bbef683551e19f329f60456b13a558132f/Formula/icu4c.rb

例如,版本64.2:

brew reinstall https://raw.githubusercontent.com/Homebrew/homebrew-core/a806a621ed3722fb580a58000fb274a2f2d86a6d/Formula/icu4c.rb

更新:

Homebrew的新版本可能要求您先下载该文件。如果是这样:

wget https://raw.githubusercontent.com/Homebrew/homebrew-core/a806a621ed3722fb580a58000fb274a2f2d86a6d/Formula/icu4c.rb
brew reinstall icu4c.rb