运行iron-node时,module.js找不到模块

我正在尝试使用iron-node(v2.2.17)来debugging我的摩卡unit testing。 从我的package.json运行这个命令时,unit testing运行正常:

"test": "cross-env NODE_ENV=test mocha test/.setup.js --reporter progress --compilers js:babel-core/register --require babel-polyfill --recursive \"./src/**/*.spec.js\" \"./src/**/*.integrationSpec.js\" \"./test/**/*.spec.js\"", 

但是,当我运行这个命令时,testing失败:

 "debug:test": "cross-env NODE_ENV=test iron-node node_modules\\mocha\\bin\\_mocha test/.setup.js --reporter progress --compilers js:babel-core/register --require babel-polyfill --recursive \"./src/**/*.spec.js\" \"./src/**/*.integrationSpec.js\" \"./test/**/*.spec.js\"", 

控制台中的错误是:

 Error: Cannot find module 'src/framework/api/entityAddresses/entityAddressesAc tions' - module.js:16 require internal/module.js:16:19 - entityAddressesActions.spec.js:5 Object.<anonymous> entityAddressesActions.spec.js:5:1 

该模块位于C:\TFS\Dev-UI\WebApp\Src\Web\Web\src\framework\api\entityAddresses\entityAddressesActions.js

我的项目文件夹是C:\TFS\Dev-UI\WebApp\Src\Web\Web ,我的process.env.NODE_PATH也是C:\TFS\Dev-UI\WebApp\Src\Web\Web 。 (这是未定义的,但我把它设置为process.cwd()在我的.iron-node.js – 请参阅https://github.com/sa/iron-node/issues/98#issuecomment-218658236 )

我无法弄清楚为什么没有find该模块。 我是否缺less一些configuration?

编辑

这个SO的答案build议设置process.env.NODE_PATH一旦应用程序已经开始将无法正常工作,因为模块path被caching: 确定从一个正在运行的node.js应用程序的项目根

在铁节点启动之前如何设置这个问题,我感到茫然,它总是未定义的

问题可以用.iron-node.jsconfiguration文件解决:

 process.env.NODE_PATH = process.cwd(); // fix problem where modules are not resolved - Jack Allan. var path = require("path"); var settings = { "nodeModule" : { "scriptInjection" : "module.paths.push(process.env.NODE_PATH);", // fix problem where modules are not resolved - Jack Allan. }, "v8": { "flags" : [ // DEFAULT=[]; https://github.com/thlorenz/v8-flags/blob/master/flags-0.11.md ] }, "app": { "native+" : false, // DEFAULT=FALSE; extends require to search native modules respecting the current v8 engine version. "autoAddWorkSpace" : false, // DEFAULT=TRUE; disables the autoAddWorkSpace behavior. "openDevToolsDetached" : false, // DEFAULT=FALSE; opens the dev tools windows detached in an own window. "hideMainWindow" : false, // DEFAULT=FALSE; hides the main window to show dev tools only. }, "workSpaceDirectory" : function(argv) { // determines the workspace directory for specific commandline applications. var result = ""; if (argv[2]){ result = path.dirname(argv[2]); var startupScriptName = path.basename(argv[2]).toLowerCase(); switch(startupScriptName) { case "_mocha": result = process.cwd(); break; default: result = path.resolve(result); break; } } return result; } }; module.exports = settings; 

感谢sa谁build议这个: https : //github.com/sa/iron-node/issues/98#issuecomment-218712907