【问题标题】:Hapi complains about a missing plugin dependency that is installedHapi 抱怨缺少安装的插件依赖项
【发布时间】:2020-04-08 03:40:19
【问题描述】:

启动我的程序时,我得到:

Error: Plugin routes-api-cruises missing dependency @hapi/nes
    at new module.exports (/usr/src/app/node_modules/@hapi/hoek/lib/error.js:23:19)
    at Object.module.exports [as assert] (/usr/src/app/node_modules/@hapi/hoek/lib/assert.js:20:11)
    at module.exports.internals.Core._validateDeps (/usr/src/app/node_modules/@hapi/hapi/lib/core.js:348:22)
    at module.exports.internals.Core._initialize (/usr/src/app/node_modules/@hapi/hapi/lib/core.js:320:14)
    at module.exports.internals.Core._start (/usr/src/app/node_modules/@hapi/hapi/lib/core.js:240:24)
    at internals.Server.start (/usr/src/app/node_modules/@hapi/hapi/lib/server.js:523:27)
    at startServer (/usr/src/app/server.js:12:21)
    at processTicksAndRejections (internal/process/task_queues.js:85:5)

我不知道“插件x缺少依赖y”是否意味着插件未能声明它使用的依赖,或者是否声明的依赖没有安装

看起来插件声明了它的依赖:

exports.plugin = {
  name: 'routes-api-cruises',
  dependencies: ['hapi-mongodb', '@hapi/nes'],  // <- there it is
  ...
}

好像也安装了包:

$ find node_modules -iname 'nes'
node_modules/@hapi/nes

package.json 包括:

"dependencies": {
   "@hapi/nes": "^11.2.1",
   ...
}

package-lock.json 包括:

@hapi/nes": {
      "version": "11.2.2",
      "resolved": "https://registry.npmjs.org/@hapi/nes/-/nes-11.2.2.tgz",
      "integrity": "sha512-XGFfTQsBB7NnpIgVdnz36lrZjJlUgni0tLmcN4TWiYdCGxNr6+YRreQ6jdsGN3j8qfZ8yLBY0FsGkHBiMPKLAw==",
      ...
}

代码使用@hapi/gluecompose() 函数并传入要注册的插件列表,并且存在@hapi/nes

【问题讨论】:

    标签: node.js hapijs


    【解决方案1】:

    我在 Hapi 源代码中找到了source of that error,并使用 Node 检查器在此处附加了一个断点。

    函数_validateDeps 枚举每个插件声明的依赖关系。它在this.registrations 中查找这些插件注册地图。

    this.registrations 中,@hapi/nes 显示为简单的nes。将插件依赖声明更改为简单的nes 即可进行查找。

    【讨论】:

      猜你喜欢
      • 2022-08-04
      • 2021-12-19
      • 1970-01-01
      • 2018-06-18
      • 2015-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-08
      相关资源
      最近更新 更多