Help us understand the problem. What is going on with this article?

node-iconvのインストールで若干詰まったメモ

More than 3 years have passed since last update.

過去にNode.jsでメールを取得する記事を書きましたが、

Node.jsで社内日報メールを取得してFacebookページに自動投稿する仕組みを実装したので解説します。

久々にやろうとしてnode-iconvのインストールでこけたのでメモ。(前にどっかで書いてるかも。。。?)

https://github.com/bnoordhuis/node-iconv

環境

  • CentOS 7系
  • Node.js v4.1.2

流れと解決

$ npm i --save iconv

こんな感じのエラーログが出ました。

npm WARN package.json mail@1.0.0 No description
npm WARN package.json mail@1.0.0 No repository field.
npm WARN package.json mail@1.0.0 No README data
|
> iconv@2.1.11 install /root/mail/node_modules/iconv
> node-gyp rebuild

make: ディレクトリ `/root/mail/node_modules/iconv/build' に入ります
  CC(target) Release/obj.target/libiconv/deps/libiconv/lib/iconv.o
make: cc: コマンドが見つかりませんでした
make: *** [Release/obj.target/libiconv/deps/libiconv/lib/iconv.o] エラー 127
make: ディレクトリ `/root/mail/node_modules/iconv/build' から出ます
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/root/.nvm/versions/node/v4.1.2/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:270:23)
gyp ERR! stack     at emitTwo (events.js:87:13)
gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Linux 3.10.0-229.el7.x86_64
gyp ERR! command "/root/.nvm/versions/node/v4.1.2/bin/node" "/root/.nvm/versions/node/v4.1.2/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /root/mail/node_modules/iconv
gyp ERR! node -v v4.1.2
gyp ERR! node-gyp -v v3.0.3
gyp ERR! not ok
npm ERR! Linux 3.10.0-229.el7.x86_64
npm ERR! argv "/root/.nvm/versions/node/v4.1.2/bin/node" "/root/.nvm/versions/node/v4.1.2/bin/npm" "i" "--save" "iconv"
npm ERR! node v4.1.2
npm ERR! npm  v2.14.4
npm ERR! code ELIFECYCLE

npm ERR! iconv@2.1.11 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the iconv@2.1.11 install script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the iconv package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls iconv
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /root/mail/npm-debug.log

cc: コマンドが見つかりませんでしたって書いてるところがポイントっぽいですね。
この辺覗くと、node-iconvは内部がCで書かれてるっぽいですね、ccgccといったコンパイラが無いからうまくビルドでき無いみたいです。

yumでgccをインストールしましょう。

$ yum install gcc

再チャレンジ

$ npm i --save iconv
npm WARN package.json mail@1.0.0 No description
npm WARN package.json mail@1.0.0 No repository field.
npm WARN package.json mail@1.0.0 No README data
/
> iconv@2.1.11 install /root/mail/node_modules/iconv
> node-gyp rebuild

make: ディレクトリ `/root/mail/node_modules/iconv/build' に入ります
  CC(target) Release/obj.target/libiconv/deps/libiconv/lib/iconv.o
  AR(target) Release/obj.target/iconv.a
  COPY Release/iconv.a
  CXX(target) Release/obj.target/iconv/src/binding.o
make: g++: コマンドが見つかりませんでした
make: *** [Release/obj.target/iconv/src/binding.o] エラー 127
make: ディレクトリ `/root/mail/node_modules/iconv/build' から出ます
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/root/.nvm/versions/node/v4.1.2/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:270:23)
gyp ERR! stack     at emitTwo (events.js:87:13)
gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Linux 3.10.0-229.el7.x86_64
gyp ERR! command "/root/.nvm/versions/node/v4.1.2/bin/node" "/root/.nvm/versions/node/v4.1.2/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /root/mail/node_modules/iconv
gyp ERR! node -v v4.1.2
gyp ERR! node-gyp -v v3.0.3
gyp ERR! not ok
npm ERR! Linux 3.10.0-229.el7.x86_64
npm ERR! argv "/root/.nvm/versions/node/v4.1.2/bin/node" "/root/.nvm/versions/node/v4.1.2/bin/npm" "i" "--save" "iconv"
npm ERR! node v4.1.2
npm ERR! npm  v2.14.4
npm ERR! code ELIFECYCLE

npm ERR! iconv@2.1.11 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the iconv@2.1.11 install script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the iconv package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls iconv
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /root/mail/npm-debug.log

make: g++: コマンドが見つかりませんでしたって出ました。

g++をCentOSへインストールする

g++コマンドが無いらしいのでインストールします。

$ yum -y install gcc-c++

これでg++が使えるようになったので再度チャレンジ

$ npm i --save iconv
npm WARN package.json mail@1.0.0 No description
npm WARN package.json mail@1.0.0 No repository field.
npm WARN package.json mail@1.0.0 No README data
-
> iconv@2.1.11 install /root/mail/node_modules/iconv
> node-gyp rebuild

make: ディレクトリ `/root/mail/node_modules/iconv/build' に入ります
  CC(target) Release/obj.target/libiconv/deps/libiconv/lib/iconv.o
  AR(target) Release/obj.target/iconv.a
  COPY Release/iconv.a
  CXX(target) Release/obj.target/iconv/src/binding.o
  SOLINK_MODULE(target) Release/obj.target/iconv.node
  COPY Release/iconv.node
make: ディレクトリ `/root/mail/node_modules/iconv/build' から出ます
iconv@2.1.11 node_modules/iconv
└── nan@2.0.9

これでうまくインストールされました。

お疲れ様です!

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした