node-odbc icon indicating copy to clipboard operation
node-odbc copied to clipboard

Npm install fails in Alpine Docker....

Open guzman-raphael opened this issue 7 years ago • 8 comments

I am having an issue when trying to install the module in an Alpine Docker container.

Here is the error:

[email protected] install /app/node_modules/odbc node-gyp configure build

make: Entering directory '/app/node_modules/odbc/build' CXX(target) Release/obj.target/odbc_bindings/src/odbc.o ../src/odbc.cpp: In static member function 'static void ODBC::UV_AfterCreateConnection(uv_work_t*, int)': ../src/odbc.cpp:201:27: warning: 'v8::Localv8::Value Nan::Callback::Call(int, v8::Localv8::Value) const' is deprecated [-Wdeprecated-declarations] data->cb->Call(1, info); ^ In file included from ../src/odbc.h:23:0, from ../src/odbc.cpp:25: ../../nan/nan.h:1647:3: note: declared here Call(int argc, v8::Localv8::Value argv[]) const { ^~~~ ../src/odbc.cpp:213:48: warning: 'v8::Localv8::Value Nan::Callback::Call(v8::Localv8::Object, int, v8::Localv8::Value) const' is deprecated [-Wdeprecated-declarations] data->cb->Call(data->dbo->handle(), 2, info); ^ In file included from ../src/odbc.h:23:0, from ../src/odbc.cpp:25: ../../nan/nan.h:1625:3: note: declared here Call(v8::Localv8::Object target ^~~~ ../src/odbc.cpp: In static member function 'static v8::Handlev8::Value ODBC::GetColumnValue(SQLHSTMT, Column, uint16_t*, int)': ../src/odbc.cpp:491:71: error: 'timelocal' was not declared in this scope return scope.Escape(Nan::New<Date>((double(timelocal(&timeInfo)) * 1000) ^ ../src/odbc.cpp: In static member function 'static v8::Localv8::Value ODBC::CallbackSQLError(SQLSMALLINT, SQLHANDLE, char*, Nan::Callback*)': ../src/odbc.cpp:785:19: warning: 'v8::Localv8::Value Nan::Callback::Call(int, v8::Localv8::Value*) const' is deprecated [-Wdeprecated-declarations] cb->Call(1, info); ^ In file included from ../src/odbc.h:23:0, from ../src/odbc.cpp:25: ../../nan/nan.h:1647:3: note: declared here Call(int argc, v8::Localv8::Value argv[]) const { ^~~~ make: *** [odbc_bindings.target.mk:109: Release/obj.target/odbc_bindings/src/odbc.o] Error 1 gyp ERR! build error make: Leaving directory '/app/node_modules/odbc/build' gyp ERR! stack Error: make failed with exit code: 2 gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:258:23) gyp ERR! stack at emitTwo (events.js:126:13) gyp ERR! stack at ChildProcess.emit (events.js:214:7) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12) gyp ERR! System Linux 3.10.0-514.6.1.el7.x86_64 gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "build" gyp ERR! cwd /app/node_modules/odbc gyp ERR! node -v v8.11.4 gyp ERR! node-gyp -v v3.6.2 gyp ERR! not ok npm WARN [email protected] No description npm WARN [email protected] No repository field.

npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! [email protected] install: node-gyp configure build npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the [email protected] install script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2018-09-27T20_03_08_832Z-debug.log ERROR: Service 'odbc_client' failed to build: The command '/bin/sh -c mkdir /app/log && apk update && apk add freetds unixodbc-dev && apk add python && apk add make g++ && npm install' returned a non-zero code: 1


Dockerfile contents:

FROM node:8.11.4-alpine WORKDIR /app COPY ./package.json ./ RUN
mkdir /app/log &&
apk update &&
apk add freetds unixodbc-dev &&
apk add python &&
apk add make g++ &&
npm install ENV PATH ./node_modules/.bin:$PATH CMD ["top"]


package.json contents:

{ "name": "adapter", "version": "1.0.0", "description": "", "main": "app.js", "scripts": { "start": "node src/app.js", "test": "node src/test.js" }, "author": "", "license": "ISC", "dependencies": { "cron": "^1.4.1", "moment-timezone": "^0.5.21", "mqtt": "^2.18.3", "odbc": "^1.4.5", "winston": "^3.0.0" } }

guzman-raphael avatar Sep 27 '18 20:09 guzman-raphael

I'm getting the same thing when using npm to install odbc:

../src/odbc.cpp:491:71: error: 'timelocal' was not declared in this scope return scope.Escape(Nan::New<Date>((double(timelocal(&timeInfo)) * 1000)

Possibly configure related?

ninthclowd avatar Oct 13 '18 23:10 ninthclowd

I eventually got it to work by making one change to the odbc.cpp file. I'll try to make a pull request for it soon.

Moved the line "#define timelocal mktime" outside of the if block in line 489. I'm sure this has implications in other environments but works in alpine with no issues.

Just make sure to clone this repo and install from local repo in Node.

Raphael

guzman-raphael avatar Oct 14 '18 18:10 guzman-raphael

Had this error today and Upgrading to v2.0.0-beta.0 fixed it. Woohoo!

Edit: Also using Alpine.

Fenderis avatar Apr 22 '19 22:04 Fenderis

@Fenderis as you use 2.0.0 beta, feel free to post any issues you run into. Very interested in making it the next-gen for ODBC on Node.js!

markirish avatar Apr 22 '19 23:04 markirish

Tried using it as it seemed to have compiled properly as mentionned earlier.

Unfortunately, It couldn't seem to be able to make it work.

By doing : var db = require("odbc")(); Got : fatal error require(...) is not a function.

When doing: require("odbc"); had an object with these properties [ 'Pool', 'Connection' ]

I ended up changing docker base image to debian instead of alpine, returned to version 1.4.6 of odbc and seems to work now.

Fenderis avatar Apr 23 '19 16:04 Fenderis

@Fenderis

So the API for odbc 2.0 is a little different, and can be found here (if you are interested in using the new API): https://www.npmjs.com/package/odbc/v/2.0.0-beta.1 Note to create a connection, you can call

{ Connection } = require('odbc');
const conn = new Connection(connectionString;);
cont result =  await conn.query('YOUR QUERY);

or to create a Pool

{ Pool } = require('odbc');
const pool = new Pool(connectionString);
await pool.init();
const result = pool.query('YOUR QUERY');

Both the examples above use the await syntax so will have to be used inside a function labeled with async. You can also use traditional callbacks, or .then/.catch Promise syntax.

markirish avatar Apr 23 '19 16:04 markirish

Following this since we're having the same issue with alpine docker. We will try switching to ubuntu image first, and if that fails try patching the odbc.cpp as per @guzman-raphael

otang avatar Jan 06 '20 22:01 otang

FYI switching to standard node docker slim worked well for us.

otang avatar Jan 07 '20 08:01 otang