首页 > 解决方案 > 在 node.js 应用程序中启动时找不到绑定文件

问题描述

我有一个旧node.js应用程序,我正在复活几年前写的。我正在更新其中的包和依赖项,但我遇到了一个阻止程序运行的主要问题。

每次我尝试在myApplication文件夹内使用node app.js或启动应用程序时nodemon,我都会收到以下错误 22 次:

{ Error: Could not locate the bindings file. Tried:
    → /Users/myUser/folder/myApplication/node_modules/bson-ext/build/bson.node
    → /Users/myUser/folder/myApplication/node_modules/bson-ext/build/Debug/bson.node
    → /Users/myUser/folder/myApplication/node_modules/bson-ext/build/Release/bson.node
    → /Users/myUser/folder/myApplication/node_modules/bson-ext/out/Debug/bson.node
    → /Users/myUser/folder/myApplication/node_modules/bson-ext/Debug/bson.node
    → /Users/myUser/folder/myApplication/node_modules/bson-ext/out/Release/bson.node
    → /Users/myUser/folder/myApplication/node_modules/bson-ext/Release/bson.node
    → /Users/myUser/folder/myApplication/node_modules/bson-ext/build/default/bson.node
    → /Users/myUser/folder/myApplication/node_modules/bson-ext/compiled/11.13.0/darwin/x64/bson.node
    → /Users/myUser/folder/myApplication/node_modules/bson-ext/addon-build/release/install-root/bson.node
    → /Users/myUser/folder/myApplication/node_modules/bson-ext/addon-build/debug/install-root/bson.node
    → /Users/myUser/folder/myApplication/node_modules/bson-ext/addon-build/default/install-root/bson.node
    → /Users/myUser/folder/myApplication/node_modules/bson-ext/lib/binding/node-v67-darwin-x64/bson.node
       at bindings (/Users/myUser/folder/myApplication/node_modules/bindings/bindings.js:126:9)
       at Object.<anonymous> (/Users/myUser/folder/myApplication/node_modules/bson-ext/ext/index.js:10:30)
       at Module._compile (internal/modules/cjs/loader.js:805:30)
       at Object.Module._extensions..js (internal/modules/cjs/loader.js:816:10)
       at Module.load (internal/modules/cjs/loader.js:672:32)
       at tryModuleLoad (internal/modules/cjs/loader.js:612:12)
       at Function.Module._load (internal/modules/cjs/loader.js:604:3)
       at Module.require (internal/modules/cjs/loader.js:711:19)
       at require (internal/modules/cjs/helpers.js:14:16)
       at Object.<anonymous> (/Users/myUser/folder/myApplication/node_modules/bson-ext/index.js:1:12)
     tries:
      [ '/Users/myUser/folder/myApplication/node_modules/bson-ext/build/bson.node',
        '/Users/myUser/folder/myApplication/node_modules/bson-ext/build/Debug/bson.node',
        '/Users/myUser/folder/myApplication/node_modules/bson-ext/build/Release/bson.node',
        '/Users/myUser/folder/myApplication/node_modules/bson-ext/out/Debug/bson.node',
        '/Users/myUser/folder/myApplication/node_modules/bson-ext/Debug/bson.node',
        '/Users/myUser/folder/myApplication/node_modules/bson-ext/out/Release/bson.node',
        '/Users/myUser/folder/myApplication/node_modules/bson-ext/Release/bson.node',
        '/Users/myUser/folder/myApplication/node_modules/bson-ext/build/default/bson.node',
        '/Users/myUser/folder/myApplication/node_modules/bson-ext/compiled/11.13.0/darwin/x64/bson.node',
        '/Users/myUser/folder/myApplication/node_modules/bson-ext/addon-build/release/install-root/bson.node',
        '/Users/myUser/folder/myApplication/node_modules/bson-ext/addon-build/debug/install-root/bson.node',
        '/Users/myUser/folder/myApplication/node_modules/bson-ext/addon-build/default/install-root/bson.node',
        '/Users/myUser/folder/myApplication/node_modules/bson-ext/lib/binding/node-v67-darwin-x64/bson.node' ] }

一些背景资料:

sw_vers
    ProductName:    Mac OS X
    ProductVersion: 10.14.3
    BuildVersion:   18D109
node -v
    v11.13.0
npm -v
    6.7.0

我已经尝试了很多方法来让它工作,并且经历了各种其他堆栈溢出线程。最初我尝试使用:

npm update
npm install

这将所有包更新为当前形式,但并没有消除错误。我确保xcode-select已安装和更新。仍然,同样的错误。

我继续删除整个node_modules文件夹并使用以下代码重建它:

npm install node-gyp -g
npm cache clean -f
rm -rf node_modules
npm install

我得到以下安装运行时输出,告诉我存在bson-extnode bin/postinstall

> fsevents@1.2.7 install /Users/myUser/folder/myApplication/node_modules/fsevents
> node install

node-pre-gyp WARN Using request for node-pre-gyp https download 
[fsevents] Success: "/Users/myUser/folder/myApplication/node_modules/fsevents/lib/binding/Release/node-v67-darwin-x64/fse.node" is installed via remote

> bson-ext@1.0.5 install /Users/myUser/folder/myApplication/node_modules/bson-ext
> (node-gyp rebuild 2> builderror.log) || (exit 0)


> nodemon@1.18.10 postinstall /Users/myUser/folder/myApplication/node_modules/nodemon
> node bin/postinstall || exit 0

added 1044 packages from 1088 contributors and audited 15069 packages in 10.556s
found 0 vulnerabilities

我仍然遇到同样的失败。作为说明,我尝试对node-gyp.

我专门调出了有问题的包,bson-ext并用来npm重新安装它

npm install bson-ext

我也去了node-gyp兔子python

node-gyp rebuild
    gyp info it worked if it ends with ok
    gyp info using node-gyp@3.8.0
    gyp info using node@11.13.0 | darwin | x64
    gyp http GET https://nodejs.org/download/release/v11.13.0/node-v11.13.0-headers.tar.gz
    gyp http 200 https://nodejs.org/download/release/v11.13.0/node-v11.13.0-headers.tar.gz
    gyp http GET https://nodejs.org/download/release/v11.13.0/SHASUMS256.txt
    gyp http 200 https://nodejs.org/download/release/v11.13.0/SHASUMS256.txt
    gyp info spawn /usr/local/bin/python2
    gyp info spawn args [ '/usr/local/lib/node_modules/node-gyp/gyp/gyp_main.py',
    gyp info spawn args   'binding.gyp',
    gyp info spawn args   '-f',
    gyp info spawn args   'make',
    gyp info spawn args   '-I',
    gyp info spawn args   '/Users/myUser/folder/myApplication/build/config.gypi',
    gyp info spawn args   '-I',
    gyp info spawn args   '/usr/local/lib/node_modules/node-gyp/addon.gypi',
    gyp info spawn args   '-I',
    gyp info spawn args   '/Users/myUser/.node-gyp/11.13.0/include/node/common.gypi',
    gyp info spawn args   '-Dlibrary=shared_library',
    gyp info spawn args   '-Dvisibility=default',
    gyp info spawn args   '-Dnode_root_dir=/Users/myUser/.node-gyp/11.13.0',
    gyp info spawn args   '-Dnode_gyp_dir=/usr/local/lib/node_modules/node-gyp',
    gyp info spawn args   '-Dnode_lib_file=/Users/myUser/.node-gyp/11.13.0/<(target_arch)/node.lib',
    gyp info spawn args   '-Dmodule_root_dir=/Users/myUser/folder/myApplication',
    gyp info spawn args   '-Dnode_engine=v8',
    gyp info spawn args   '--depth=.',
    gyp info spawn args   '--no-parallel',
    gyp info spawn args   '--generator-output',
    gyp info spawn args   'build',
    gyp info spawn args   '-Goutput_dir=.' ]
    gyp: binding.gyp not found (cwd: /Users/myUser/folder/myApplication) while trying to load binding.gyp
    gyp ERR! configure error 
    gyp ERR! stack Error: `gyp` failed with exit code: 1
    gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/lib/node_modules/node-gyp/lib/configure.js:345:16)
    gyp ERR! stack     at ChildProcess.emit (events.js:193:13)
    gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:255:12)
    gyp ERR! System Darwin 18.2.0
    gyp ERR! command "/usr/local/Cellar/node/11.13.0/bin/node" "/usr/local/bin/node-gyp" "rebuild"
    gyp ERR! cwd /Users/myUser/folder/myApplication
    gyp ERR! node -v v11.13.0
    gyp ERR! node-gyp -v v3.8.0
    gyp ERR! not ok

我还获取了丢失文件的旧版本bson.node,并将其粘贴到/Users/myUser/folder/myApplication/node_modules/bson-ext/build/目录中。它通知说它是使用旧节点版本构建的,因此应用程序将无法运行。

package.json文件包含适当的依赖项:

{
  "name": "myApplication",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node ./bin/www"
  },
  "dependencies": {
    "angular-daterangepicker": "^0.2.3-alpha1",
    "angular-nvd3": "^1.0.9",
    "bindings": "^1.5.0",
    "body-parser": "^1.18.3",
    "bootstrap-daterangepicker": "^2.1.30",
    "bson": "^4.0.2",
    "bson-ext": "^1.0.5",
    "cookie-parser": "^1.4.4",
    "debug": "^3.2.6",
    "express": "^4.16.4",
    "grunt": "^1.0.4",
    "jquery": "^3.3.1",
    "moment": "^2.24.0",
    "mongodb-extended-json": "^1.10.1",
    "mongoose": "^5.4.20",
    "morgan": "^1.9.1",
    "node-gyp": "^3.8.0",
    "nodemon": "^1.18.10",
    "npm": "^6.9.0",
    "pug": "^2.0.3",
    "selectize": "^0.12.6",
    "serve-favicon": "^2.5.0"
  }
}

如何解决我遇到的问题以便该程序运行?有什么方法是我想念的bson.node吗?

标签: node.jsnpmbinding

解决方案


问题出在bson-ext. 我的应用程序正在搜索 version 1.0.5,而 version2.0.1是最新版本。这解决了问题。

的版本1.0.5bson-ext有内部依赖关系nan@2.4.0,但与node@v11.


推荐阅读