NodeJS npm sqlite 3.1.1依赖使用了错误版本的节点和node-gyp

时间:2016-01-21 17:01:49

标签: node.js sqlite npm centos6.5

我试图在没有网络访问权限的机器上构建私有NodeJS包。 因此,我正在尝试构建的机器上有几个版本的节点(0.10.26和其他一些......)。

所以我这样做的方法是将offline-npm-0.2.0.tgz捆绑到我们的包中,其中包含一个包含所有依赖项的完整缓存文件夹,然后安装并运行offline-npm-0.2.0指向缓存目录,这似乎运行良好,所有依赖项都从本地主机服务器中提取。

问题是我正在构建的软件包需要节点v0.12.7,它也与它捆绑在一起,因此当我使用node和npm时,我指向使用软件包下拉的完整路径。

问题是,当涉及到构建sqlite3.1.1时,它似乎是这样做但是使用了错误版本的节点,我不知道从哪里读取它...

这是我的npm配置的样子:

[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"

因此,从上面可以看到npm配置版本的节点是v0.12.7应该是,但是当涉及到安装sqlite3.1.1时,它以某种方式使用v.0.10.26:

[Step 1/2] npm info install sqlite3@3.1.1
[12:27:29][Step 1/2] 
[12:27:29][Step 1/2] > sqlite3@3.1.1 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 node-pre-gyp@0.6.14
[12:27:29][Step 1/2] node-pre-gyp info using node@0.10.26 | 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 node-gyp@0.12.2
[12:27:29][Step 1/2] gyp info using node@0.10.26 | 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 node-gyp@0.12.2

似乎构建正常,但是当进行单元测试时,它会失败:

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

构建模块的路径实际上是: /Users/xxx/buildAgent/work/c5a68e1c6d1f0013/build/install/bin/node_modules/my_package/node_modules/sqlite3/lib/binding/node-v11-linux-x64/node_sqlite3.node

为什么使用节点0.10.26而不是0.12.7是个大问题。

1 个答案:

答案 0 :(得分:0)

问题是我正在使用与项目捆绑在一起的构建,通过提供节点可执行文件的完整路径,而系统上节点的默认安装是不同的,当node-gyp / node-pre -gyp运行它使用系统默认版本而不是项目打包的版本。解决方案是更新PATH环境变量并将捆绑节点置于系统默认值之前:

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