我使用自制(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,但问题仍然存在


当前回答

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

去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

其他回答

运行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

学分

Leland的答案对我来说很管用,但我不得不把第4步和第6步改为:

4) git checkout -B icu4c-62.1 575eb4b

6) brew重装Formula/icu4c.rb

我的问题:

# 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

在最新的OS X更新后,似乎不可能使用brew链接icu4c。这让事情变得更有趣。我找到的唯一解决办法是:

下载并编译icu4c 62.1到/usr/local/icu4c/62.1

mkdir ~/sources
cd ~/sources
wget http://download.icu-project.org/files/icu4c/62.1/icu4c-62_1-src.tgz
tar xvzf icu4c-62_1-src.tgz
cd icu/source/

sudo mkdir /usr/local/icu4c/62.1
./configure --prefix=/usr/local/icu4c/62.1
make
sudo make install

链接库:

ln -s /usr/local/icu4c/62.1/lib/*.dylib /usr/local/include/

在~/.bash_profile中设置DYLD_LIBRARY_PATH:

export DYLD_LIBRARY_PATH=/usr/local/include

在OSX 10.15.4上运行xcode-select——install修复了这个问题。