【问题标题】:Cannot find module 'sonar-request' from 'api.js' when I run npm run test当我运行 npm run test 时,无法从 'api.js' 中找到模块 'sonar-request'
【发布时间】:2018-01-18 13:00:01
【问题描述】:

当我在我的 Sonarqube 插件上运行测试时,如果一个类调用了 api,它会返回一个错误,但是当没有调用 api 时,它工作得很好。 这是错误:

FAIL  src\main\js\__tests__\Cards-test.js
Test suite failed to run

Cannot find module 'sonar-request' from 'api.js'

  at Resolver.resolveModule (node_modules\jest-resolve\build\index.js:151:17)
  at Object.<anonymous> (src\main\js\api.js:176:81)
  at Object.<anonymous> (src\main\js\components\Cards.js:2:38)

我该如何纠正这个错误?

【问题讨论】:

  • 请将错误信息添加为文本,不要添加图片。

标签: node.js testing npm sonarqube


【解决方案1】:

从错误消息看来,api.js 是您自己编码的一部分(不是依赖项)。

您引用了计算机上的 sonar-request 模块,根据您的错误消息,该模块不存在。通常,您需要npm install 它。但是registry 上没有这样的模块(发帖时)

请检查您的 api.js 文件中提到的 require 语句(您可以在第 176 行找到它)。

【讨论】:

  • 我正在尝试按照以下示例测试我的 Sonarqube 插件:link。他们使用 api.js 文件来请求 Web 服务。在我测试课程之前它工作得很好,它向我显示了这个错误!
猜你喜欢
  • 2021-09-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-05
  • 2022-01-26
  • 2021-11-04
  • 2018-01-28
相关资源
最近更新 更多