module.js在运行iron节点时找不到模块
module.js cannot find modules when running iron-node
我正在尝试使用iron node(v2.2.17)来调试我的mocha单元测试。当我从包.json:中运行此命令时,单元测试运行良好
"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'"",
然而,当我运行此命令时,测试失败:
"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
。(它是未定义的,但我在.iron-node.js
中将它设置为process.cwd()
-请参阅https://github.com/s-a/iron-node/issues/98#issuecomment-218658236)
我不明白为什么找不到模块。我是否缺少某些配置?
编辑
SO的回答表明,一旦应用程序启动,设置process.env.NODE_PATH
将不起作用,因为模块路径已缓存:从正在运行的node.js应用程序中确定项目根
我不知道如何在iron节点启动之前设置它,它总是未定义的
问题可以通过.iron-node.js配置文件解决:
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;
感谢提出以下建议的s-a:https://github.com/s-a/iron-node/issues/98#issuecomment-218712907
相关文章:
- 找不到模块捆绑包
- Babel编译错误:找不到模块核心js/library/fn/get迭代器
- 因果报应-找不到模块:错误:无法解析模块'scs'
- module.js在运行iron节点时找不到模块
- 错误:找不到模块'/lib/cli'
- nodeJS中的uglify js“;找不到模块“”;
- 找不到模块'它'当用摩卡/柴测试时
- 余烬引擎未捕获错误:找不到模块余烬视图/views/select
- 使用状态语法后找不到模块
- 节点.js:找不到模块“柴”
- 错误:使用摩卡测试时找不到模块
- nodemon找不到模块'/路径/to/project/home/index.js'
- 接收'错误:找不到模块'使用browserfy、gullow、react.js
- Sails.js+Grunt"找不到模块“”;错误
- 找不到模块“;睡眠”;,跳跃动作
- 找不到模块 './build/Release/bson'] 代码: 'MODULE_NOT_FOUND' } js-bs
- 错误:找不到模块'开放星云'(Meteor.JS)
- 错误:找不到模块,但仅在Heroku上
- 错误:找不到模块'html',可以't提供静态文件
- Gulp测试找不到模块