为什么 Mocha.js 找不到模块?

Why Mocha.js can't find the module ?

我不明白为什么 mocha.js 找不到我的路径! 这是我在节点课程项目中包含的文件结构

  ///////Root
  --package.json
  --node_modules/
  --playground
  --server
     -server.js
     -db
     -models
     -tests
           ---server.test.js

每次我 运行 "mocha server/**/*.test.js" 在从命令提示符 运行 执行测试命令后,我从命令提示符得到这个错误:

    > todo-api@1.0.0 test C:\Users\Omar Ali\Desktop\node-todo-api
> mocha server/**/*.test.js

module.js:549
    throw err;
    ^

Error: Cannot find module '../server/server'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Users\Omar Ali\Desktop\node-todo-api\server\tests\
server.test.js:6:9)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at C:\Users\Omar Ali\Desktop\node-todo-api\node_modules\mocha\lib\mocha.js:2
50:27
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (C:\Users\Omar Ali\Desktop\node-todo-api\node_modules\moc
ha\lib\mocha.js:247:14)
    at Mocha.run (C:\Users\Omar Ali\Desktop\node-todo-api\node_modules\mocha\lib
\mocha.js:576:10)
    at Object.<anonymous> (C:\Users\Omar Ali\Desktop\node-todo-api\node_modules\
mocha\bin\_mocha:637:18)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! todo-api@1.0.0 test: `mocha server/**/*.test.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the todo-api@1.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional log
ging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Omar Ali\AppData\Roaming\npm-cache\_logs18-07-28T18_00_
44_790Z-debug.log

感谢您展示结构,它应该是 ../server../server.js,因为您的 server 模块(或文件)位于测试脚本。