【问题标题】:Cannot find module 'commander'找不到模块“指挥官”
【发布时间】:2020-03-28 00:31:20
【问题描述】:

当我尝试运行我的 mocha 测试时,我得到了

$ npm t

> digitalAlarmClock@1.0.0 test /home/durrantm/Dropnot/code/js/mochaChai/digitalAlarmClock
>  mocha *.test.js

internal/modules/cjs/loader.js:979
  throw err;
  ^

Error: Cannot find module 'commander'
Require stack:
- /usr/lib/nodejs/mocha/bin/_mocha
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:976:15)
    at Function.Module._load (internal/modules/cjs/loader.js:859:27)
    at Module.require (internal/modules/cjs/loader.js:1036:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/usr/lib/nodejs/mocha/bin/_mocha:10:17)
    at Module._compile (internal/modules/cjs/loader.js:1147:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
    at Module.load (internal/modules/cjs/loader.js:996:32)
    at Function.Module._load (internal/modules/cjs/loader.js:896:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/usr/lib/nodejs/mocha/bin/_mocha' ]
}
npm ERR! Test failed.  See above for more details.

如何解决?

【问题讨论】:

  • 我怀疑这个问题是“如果需要Mocha但未安装,那么你需要安装它”。我不确定这有多大用处,所以最好还是结束这个问题。

标签: npm mocha.js


【解决方案1】:

这是我解决问题的方法:

运行npm list,看看是否缺少依赖,比如我看到了:

[root@d21b188bb7e1 configurable-http-proxy]# npm list
configurable-http-proxy@4.3.2 /srv/configurable-http-proxy
├── UNMET DEPENDENCY commander@~7.2.0
...

手动安装

npm install --save commander@~7.2.0

【讨论】:

    【解决方案2】:

    这可能有几个不同的原因。

    在这种情况下是因为没有安装 mocha。

    修复

    npm install --save-dev mocha
    

    【讨论】:

      猜你喜欢
      • 2018-08-29
      • 2010-11-24
      • 1970-01-01
      • 2017-01-06
      • 1970-01-01
      • 2014-12-06
      • 1970-01-01
      • 2016-05-10
      • 2019-02-05
      相关资源
      最近更新 更多