Reputation: 309
I am coding a small chatbot with facebook messenger.
I created 2 main js file: facebook.js and control.js
facebook.js will perform send message/ receive message. control.js will perform some minor logic/ application function.
Let me give a example code for these two js.
In facebook.js
function sendMessage(){
///configuring and json format
//send to facebook server(webhook) by using Bluebird
return new bluebird(function(resolve, reject) {
resolve(data);
}
}
// exports sendMessage()
module.exports = {
sendMessage:sendMessage
}
control.js
var fb = require('./facebook');
function something(){
fb.sendMessage();
}
When i trigger the somthing(). The console show the error like this
System Error ### : uncaughtException: fb.sendMessage is not a function TypeError: fb.sendMessage is not a function
I log the 'fb': it print {} in console. Anyone facing this error? am i code wrong way to exports the function?
Upvotes: 1
Views: 1105
Reputation: 309
Because when i print out the "fb" .It shows empty {}
I found that is problem of circular dependency! Which means you have 2 module(Ma and Mb). Module B required by Module A. Also, Module A required by Module B
More info: enter link description here
Upvotes: 1