Wednesday, April 1, 2015

[couchbase] [nodejs 0.12] Build fail


When trying to npm install couchbase after migrating to node.js v0.12, the build process silently fails on stdout and stderr, and you get a "Failed to locate couchnode native binding" when starting your application

A quick look at "node_modules/couchbase/builderror.log"  indicates undeclared vars :
.node-gyp/0.12.0/deps/uv/include/uv.h:75:6: error: 'EAI_BADHINTS' undeclared (first use in this function)
   XX(EAI_BADHINTS, "invalid value for hints")                                 \
/home/zup/.node-gyp/0.12.0/deps/uv/include/uv.h:80:6: error: 'EAI_NODATA' undeclared (first use in this function)
   XX(EAI_NODATA, "no address")                                                \
(...)
/home/zup/.node-gyp/0.12.0/deps/uv/include/uv.h:83:6: error: 'EAI_PROTOCOL' undeclared (first use in this function)
   XX(EAI_PROTOCOL, "resolved protocol is unknown")                            \
(...)
gyp ERR! not ok
According to this post, the problem should have been fixed with libcouchbase 2.4.8, but when trying to rebuild couchnode using libcouchbase 2.4.8, you now get the following errors :
In file included from ../deps/lcb/include/libcouchbase/plugins/io/libuv/plugin-internal.h:31,
                 from ../deps/lcb/include/libcouchbase/plugins/io/libuv/plugin-libuv.c:18,
                 from ../src/uv-plugin-all.c:17:
../deps/lcb/include/libcouchbase/plugins/io/libuv/libuv_compat.h: In function 'uv_uv2syserr':
../deps/lcb/include/libcouchbase/plugins/io/libuv/libuv_compat.h:168: error: 'EAI_BADHINTS' undeclared (first use in this function)
../deps/lcb/include/libcouchbase/plugins/io/libuv/libuv_compat.h:168: error: (Each undeclared identifier is reported only once
../deps/lcb/include/libcouchbase/plugins/io/libuv/libuv_compat.h:168: error: for each function it appears in.)
../deps/lcb/include/libcouchbase/plugins/io/libuv/libuv_compat.h:168: error: 'EAI_NODATA' undeclared (first use in this function)
../deps/lcb/include/libcouchbase/plugins/io/libuv/libuv_compat.h:168: error: 'EAI_PROTOCOL' undeclared (first use in this function)
make: *** [Release/obj.target/couchbase_impl/src/uv-plugin-all.o] Error 1
gyp ERR! build error
After almost a day fighting with this issue, and thanks to Corbin Uselton for pointing me to the solution, here is how you can build the npm couchbase module when running node.js engine 0.12+

# Update libcouchbase to 2.4.8

For non CentOS distribs, adapt to your env using the official doc

## Add the couchbase yum repo  :

vi /etc/yum.repos.d/couchbase.repo
[couchbase]
name = Couchbase package repository
gpgkey = http://packages.couchbase.com/rpm/couchbase-rpm.key
enabled = 1
baseurl = http://packages.couchbase.com/rpm/6.2/x86_64
gpgcheck = 1
## Install latest libcouchbase (2.4.8 as of 20150401)
yum install libcouchbase-devel.x86_64 \  libcouchbase2-bin.x86_64 \  libcouchbase2-core.x86_64 \  libcouchbase2-libev.x86_64 \  libcouchbase2-libevent.x86_64 \  -y
# Add the missing definitions in the newly installed libcouchbase (starting at line 87)
vi /usr/include/libcouchbase/plugins/io/libuv/libuv_compat.h
(...)
#ifndef EAI_NODATA
#define EAI_NODATA EAI_FAIL
#endif
#ifndef EAI_PROTOCOL
#define EAI_PROTOCOL EAI_FAIL
#endif
(...)
# Rebuild node module couchbase using the newly installed libcouchbase 
npm install couchbase --couchbase-root=/usr

You can now start your app and make sure you do not get the "Failed to locate couchnode native binding" error message


Happy  node0.12

No comments: