【发布时间】:2014-01-11 07:49:46
【问题描述】:
我在meteor中测试代码。有一些错误。
/server/lib/Test.js
测试 = { 说:函数(){ console.log("你好世界"); } }/server/main.js
Meteor.startup(函数(){ 测试.say(); //运行良好 var path = Npm.require('path'); var base = path.resolve('.'); var n = Npm.require('child_process').fork(base+"/app/server/children.js"); n.on('消息', function(m) { console.log('家长收到消息:', m); }); n.send({你好:'世界'}); });/server/children.js
process.on('消息', function(m) { 测试.say(); //抛出一个错误。测试未定义 console.log('孩子收到消息:', m); process.send({name:"ABC"}); }); process.send({ foo: 'bar' });错误:
I20131223-16:34:44.717(8)?你好世界 W20131223-16:34:44.784(8)? (STDERR)/home/ec/workspace/meteor/testChildrenProcess/.meteor/local/build/programs/server/app/server/children.js:2 W20131223-16:34:44.784(8)? (STDERR) Test.say(); W20131223-16:34:44.785(8)? (标准错误)^ W20131223-16:34:44.785(8)? (STDERR)ReferenceError:未定义测试 W20131223-16:34:44.787(8)? (STDERR) 在处理中。 (/home/ec/workspace/meteor/testChildrenProcess/.meteor/local/build/programs/server/app/server/children.js:2:3) W20131223-16:34:44.788(8)? (STDERR) 在 process.EventEmitter.emit (events.js:98:17) W20131223-16:34:44.788(8)? (STDERR) 在 handleMessage (child_process.js:318:10) W20131223-16:34:44.788(8)? (STDERR) 在 Pipe.channel.onread (child_process.js:345:11)测试对象在“/app/server/children.js”中未定义,但在 main.js 中是正常的。 为什么?我忘了什么吗?任何帮助表示赞赏。
【问题讨论】:
标签: meteor