代码之家  ›  专栏  ›  技术社区  ›  Michael Durrant

找不到模块“commander”

  •  0
  • Michael Durrant  · 技术社区  · 6 年前

    当我试着做摩卡测试的时候

    $ 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.
    

    如何修复?

    1 回复  |  直到 6 年前
        1
  •  0
  •   Michael Durrant    6 年前

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

    在这种情况下,这是因为没有安装摩卡。

    修复

    npm install --save-dev mocha
    
    推荐文章