Search code examples
node.jssqlitenpmcentos6.5

NodeJS npm sqlite 3.1.1 dependency uses wrong version of node and node-gyp under the hood


Im trying to build a private NodeJS package on a machine without network access. So there are a few versions of node on the machine I'm attempting the build on already (0.10.26 and some others...).

So the way I'm going about this I bundle offline-npm-0.2.0.tgz into our package with a full cache folder containing all of the dependencies, then install and run offline-npm-0.2.0 pointing as the cache directory, this seems to work well and all the dependencies are pulled from a localhost server.

The thing is that the package I'm building requires node v0.12.7, which is also bundled with it, so when I use node and npm I point to the full path which is pulled down with the package.

The problem is that when it comes to building sqlite3.1.1 it seems to do it but uses the wrong version of node and I have no idea where it reads it from...

Here is what my npm config looks like:

[12:27:19][Step 1/2] ; cli configs
[12:27:19][Step 1/2] long = true
[12:27:19][Step 1/2] user-agent = "npm/2.11.3 node/v0.12.7 linux x64"
[12:27:19][Step 1/2] 
[12:27:19][Step 1/2] ; userconfig /home2/build/.npmrc
[12:27:19][Step 1/2] cache = "/Users/xxx/buildAgent/work/c5a68e1c6d1f0013/build/install/npmcache"
[12:27:19][Step 1/2] nodedir = "/Users/xxx/buildAgent/work/c5a68e1c6d1f0013/build/src/node"
[12:27:19][Step 1/2] registry = "http://localhost:4873/"
[12:27:19][Step 1/2] 
[12:27:19][Step 1/2] ; default values
[12:27:19][Step 1/2] access = null
[12:27:19][Step 1/2] always-auth = false
[12:27:19][Step 1/2] bin-links = true
[12:27:19][Step 1/2] browser = null
[12:27:19][Step 1/2] ca = null
[12:27:19][Step 1/2] ; cache = "/home2/build/.npm" (overridden)
[12:27:19][Step 1/2] cache-lock-retries = 10
[12:27:19][Step 1/2] cache-lock-stale = 60000
[12:27:19][Step 1/2] cache-lock-wait = 10000
[12:27:19][Step 1/2] cache-max = null
[12:27:19][Step 1/2] cache-min = 10
[12:27:19][Step 1/2] cafile = undefined
[12:27:19][Step 1/2] cert = null
[12:27:19][Step 1/2] color = true
[12:27:19][Step 1/2] depth = null
[12:27:19][Step 1/2] description = true
[12:27:19][Step 1/2] dev = false
[12:27:19][Step 1/2] editor = "vi"
[12:27:19][Step 1/2] engine-strict = false
[12:27:19][Step 1/2] fetch-retries = 2
[12:27:19][Step 1/2] fetch-retry-factor = 10
[12:27:19][Step 1/2] fetch-retry-maxtimeout = 60000
[12:27:19][Step 1/2] fetch-retry-mintimeout = 10000
[12:27:19][Step 1/2] force = false
[12:27:19][Step 1/2] git = "git"
[12:27:19][Step 1/2] git-tag-version = true
[12:27:19][Step 1/2] global = false
[12:27:19][Step 1/2] globalconfig = "/Users/fe/TeamCity/buildAgent/work/c5a68e1c6d1f0013/build/install/etc/npmrc"
[12:27:19][Step 1/2] globalignorefile = "/Users/fe/TeamCity/buildAgent/work/c5a68e1c6d1f0013/build/install/etc/npmignore"
[12:27:19][Step 1/2] group = 1000
[12:27:19][Step 1/2] heading = "npm"
[12:27:19][Step 1/2] https-proxy = null
[12:27:19][Step 1/2] if-present = false
[12:27:19][Step 1/2] ignore-scripts = false
[12:27:19][Step 1/2] init-author-email = ""
[12:27:19][Step 1/2] init-author-name = ""
[12:27:19][Step 1/2] init-author-url = ""
[12:27:19][Step 1/2] init-license = "ISC"
[12:27:19][Step 1/2] init-module = "/home2/build/.npm-init.js"
[12:27:19][Step 1/2] init-version = "1.0.0"
[12:27:19][Step 1/2] json = false
[12:27:19][Step 1/2] key = null
[12:27:19][Step 1/2] link = false
[12:27:19][Step 1/2] local-address = undefined
[12:27:19][Step 1/2] loglevel = "warn"
[12:27:19][Step 1/2] ; long = false (overridden)
[12:27:19][Step 1/2] message = "%s"
[12:27:19][Step 1/2] node-version = "0.12.7"
[12:27:19][Step 1/2] npat = false
[12:27:19][Step 1/2] onload-script = null
[12:27:19][Step 1/2] optional = true
[12:27:19][Step 1/2] parseable = false
[12:27:19][Step 1/2] prefix = "/Users/xxx/buildAgent/work/c5a68e1c6d1f0013/build/install"
[12:27:19][Step 1/2] production = false
[12:27:19][Step 1/2] proprietary-attribs = true
[12:27:19][Step 1/2] proxy = null
[12:27:19][Step 1/2] rebuild-bundle = true
[12:27:19][Step 1/2] ; registry = "https://registry.npmjs.org/" (overridden)
[12:27:19][Step 1/2] rollback = true
[12:27:19][Step 1/2] save = false
[12:27:19][Step 1/2] save-bundle = false
[12:27:19][Step 1/2] save-dev = false
[12:27:19][Step 1/2] save-exact = false
[12:27:19][Step 1/2] save-optional = false
[12:27:19][Step 1/2] save-prefix = "^"
[12:27:19][Step 1/2] scope = ""
[12:27:19][Step 1/2] searchexclude = null
[12:27:19][Step 1/2] searchopts = ""
[12:27:19][Step 1/2] searchsort = "name"
[12:27:19][Step 1/2] shell = "/bin/bash"
[12:27:19][Step 1/2] shrinkwrap = true
[12:27:19][Step 1/2] sign-git-tag = false
[12:27:19][Step 1/2] spin = true
[12:27:19][Step 1/2] strict-ssl = true
[12:27:19][Step 1/2] tag = "latest"
[12:27:19][Step 1/2] tag-version-prefix = "v"
[12:27:19][Step 1/2] tmp = "/Users/XXX/temp/buildTmp"
[12:27:19][Step 1/2] umask = 18
[12:27:19][Step 1/2] unicode = true
[12:27:19][Step 1/2] unsafe-perm = true
[12:27:19][Step 1/2] usage = false
[12:27:19][Step 1/2] user = 5556
[12:27:19][Step 1/2] ; user-agent = "npm/{npm-version} node/{node-version} {platform} {arch}" (overridden)
[12:27:19][Step 1/2] userconfig = "/home2/build/.npmrc"
[12:27:19][Step 1/2] version = false
[12:27:19][Step 1/2] versions = false
[12:27:19][Step 1/2] viewer = "man"

So as you can see from above npm config version of node is v0.12.7 as it should be but when it comes to installing sqlite3.1.1, it somehow uses v.0.10.26:

[Step 1/2] npm info install [email protected]
[12:27:29][Step 1/2] 
[12:27:29][Step 1/2] > [email protected] install /Users/fe/TeamCity/buildAgent/work/c5a68e1c6d1f0013/build/install/bin/node_modules/my_package/node_modules/sqlite3
[12:27:29][Step 1/2] > node-pre-gyp install --fallback-to-build
[12:27:29][Step 1/2] 
[12:27:29][Step 1/2] node-pre-gyp info it worked if it ends with ok
[12:27:29][Step 1/2] node-pre-gyp info using [email protected]
[12:27:29][Step 1/2] node-pre-gyp info using [email protected] | linux | x64
[12:27:29][Step 1/2] node-pre-gyp info build requesting source compile
[12:27:29][Step 1/2] gyp info it worked if it ends with ok
[12:27:29][Step 1/2] gyp info using [email protected]
[12:27:29][Step 1/2] gyp info using [email protected] | linux | x64
[12:27:29][Step 1/2] gyp info ok 
[12:27:29][Step 1/2] gyp info it worked if it ends with ok
[12:27:29][Step 1/2] gyp info using [email protected]

It seems to build ok, but when it comes to doing a unit test, it fails:

Error: Cannot find module '/Users/xxx/buildAgent/work/c5a68e1c6d1f0013/build/install/bin/node_modules/my_package/node_modules/sqlite3/lib/binding/node-v14-linux-x64/node_sqlite3.node'
[12:28:07][Step 1/2] make[1]: *** [CMakeFiles/my_package.dir/all] Error 2
[12:28:07][Step 1/2]     at Function.Module._resolveFilename (module.js:336:15)
[12:28:07][Step 1/2]     at Function.Module._load (module.js:278:25)
[12:28:07][Step 1/2] make: *** [all] Error 2
[12:28:07][Step 1/2]     at Module.require (module.js:365:17)
[12:28:07][Step 1/2]     at require (module.js:384:17)
[12:28:07][Step 1/2]     at Object.<anonymous> (/Users/xxx/buildAgent/work/c5a68e1c6d1f0013/build/install/bin/node_modules/my_package/node_modules/sqlite3/lib/sqlite3.js:4:15)
[12:28:07][Step 1/2]     at Module._compile (module.js:460:26)
[12:28:07][Step 1/2]     at Object.Module._extensions..js (module.js:478:10)
[12:28:07][Step 1/2]     at Module.load (module.js:355:32)
[12:28:07][Step 1/2]     at Function.Module._load (module.js:310:12)
[12:28:07][Step 1/2]     at Module.require (module.js:365:17)
[12:28:07][Step 1/2]     at require (module.js:384:17)
[12:28:07][Step 1/2] 
[12:28:07][Step 1/2] 
[12:28:07][Step 1/2] 0% tests passed, 1 tests failed out of 1

The path to the build module is actually: /Users/xxx/buildAgent/work/c5a68e1c6d1f0013/build/install/bin/node_modules/my_package/node_modules/sqlite3/lib/binding/node-v11-linux-x64/node_sqlite3.node

Why is it using node 0.10.26 instead of 0.12.7 is the big question.


Solution

  • The problem was that I was doing the build using node which was bundled with the project by providing a full path to the node executable, while the default installation of node on the system was different and when node-gyp/node-pre-gyp ran it used the system default version instead of the one packaged with the project. Solution was to update the PATH environment variable and place the bundled node ahead of the system default:

    export PATH=/Users/xxx/buildAgent/work/c5a68e1c6d1f0013/build/src/node:$PATH