[英]Nodejs - functions becomes undefined after exporting
I have this on my app.js and I am exporting the foo
object. 我在我的app.js上有这个,正在导出
foo
对象。
...some code
exports.foo = {
bar: function(){
return 'this is a test'
}
}
...some code
Then on my other test.js file I am importing it like. 然后在我的另一个test.js文件中,我将其导入。
import foo from './path/to/app';
But when I tried to use foo.bar()
I am getting this error TypeError: _app2.default.bar is not a function
但是,当我尝试使用
foo.bar()
时,出现此错误TypeError: _app2.default.bar is not a function
Can someone explain what's happening here? 有人可以解释这里发生了什么吗?
use this syntax 使用此语法
module.exports = {
bar: function(){
return 'this is a test'
}
}
var foo = require("./pathToFoo.js");
foo.bar();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.