LoginSignup
50

More than 1 year has passed since last update.

npmのエラー解決「dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.60.dylib」

Last updated at Posted at 2018-05-20

概要

コマンドラインツールをiterm2へ変更したところ(?)、npmに以下のエラーが出て使えなくなった。そのため、その原因と解決策を探ってみた。

iterm2(zsh)におけるエラー
$ npm install
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.60.dylib
  Referenced from: /usr/local/bin/node
  Reason: image not found
[1]    9366 abort      npm install

原因調査

調べてみると、macOSでは、libicucore.dylib というライブラリが提供されていて、
icu4cをインストールする必要がなくなっている。

しかし、nodeをインストールする時に、icu4cを含めてインストールしたため、
libicucore.dylib と icu4c が相互干渉してしまい、エラーが出た模様。

そもそもicu4cとはなんだ?

brewformulaによると

Description
The C and C++ languages and many operating system environments do not provide full support for Unicode and standards-compliant text handling services. Even though some platforms do provide good Unicode text handling services, portable application code can not make use of them. The ICU4C libraries fills in this gap. ICU4C provides an open, flexible, portable foundation for applications to use for their software globalization requirements. ICU4C closely tracks industry standards, including Unicode and CLDR (Common Locale Data Repository).

(Google翻訳より)CおよびC ++言語および多くのオペレーティングシステム環境では、Unicodeおよび標準に準拠したテキスト処理サービスが完全にサポートされていません。いくつかのプラットフォームが優れたUnicodeテキスト処理サービスを提供していますが、移植可能なアプリケーションコードはそれらを使用できません。 ICU4Cライブラリはこのギャップを埋める。 ICU4Cは、アプリケーションのソフトウェアグローバリゼーション要件に使用するための柔軟でオープンなオープンな基盤を提供します。 ICU4Cは、UnicodeやCLDR(Common Locale Data Repository)などの業界標準を厳密に追跡します。

とのこと。OSで足りていない部分のテキスト処理を埋めるものである模様。

ではlibicucore.dylibは?

ICU(International Components for Unicode)の動的ライブラリ。
.dylibは、動的ライブラリということを指している。

動的ライブラリとは?

動的ライブラリは、アプリのコンパイル時にはライブラリへの参照のみが記録される。 そして、ランタイム上で必要となった際に初めて読み込まれる。 そうすることにより、アプリの容量が小さくなり、また使用メモリも少なくなる。 また、ライブラリ自体とは参照でつながっているため、ライブラリが更新されると、 開発者が何もせずともユーザーは即座にそのライブラリの恩恵を受けられる。

それに対し、静的ライブラリは?

静的ライブラリは、アプリのコンパイル時にコードが実行ファイル内にコピーされる。 そのため、アプリの容量が増え、使用メモリも増加。 また、ライブラリがアップデートされても、開発者が手元のライブラリをアップデートし、 アプリを再コンパイルするまで、ユーザーはその恩恵にあずかることができない。

所感

原因はどうやらbrewでnodeをinstallしたことにありそう。
2013年からicu4cは必要ないというコメントがGithubのissueのコメントにもあったのでそれかも。確かめるにもどうやって調べればいいのかわからないので、模索中。

dyldだからこそ、参照がうまくいかず、libraryが見つからなくてこのようなエラーが出ているのではないか。と考えている。(例によってあっているかまだ確かめていない。)同じようなことがxcodeやbrewを使ってインストールしたphpなどでもおこっている。

ネットでよくある解決方法

解決方法1
brew reinstall node

参考: Macでnpmとかnodeが使えなくなった。エラー(dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.58.dylib)

解決方法2
brew reinstall node --without-icu4c

または

解決方法3
brew upgrade node

参考: nodeでdyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.59.dylibとなったときの対処法
node 7.7.4 builds but throws Abort trap: 6, trying to load dyld libicui18n.58.dylib #11713

解決方法4
brew uninstall –-ignore-dependencies node icu4c
brew uninstall –-force icu4c
brew install node

参考: 復旧方法:「dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.58.dylib」nodeのエラー

どれも結局依存関係を貼り直している。

参考

この解消方法→「dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.58.dylib」 - @suin さん
Library not loaded: libmysqlclient.18.dylib (LoadError) の対処 - @wktk さん

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
50