Javascript 导入es6模块在一个文件中返回未定义,但在另一个文件中不返回
我的项目中有以下文件: Account.jsJavascript 导入es6模块在一个文件中返回未定义,但在另一个文件中不返回,javascript,node.js,ecmascript-6,babeljs,es6-modules,Javascript,Node.js,Ecmascript 6,Babeljs,Es6 Modules,我的项目中有以下文件: Account.js import User from './User'; const associations = { user: { type: 'belongsTo', model: User } }; class Account { } Account.associations = associations; export default Account; import TwitterAccount from './Twit
import User from './User';
const associations = {
user: {
type: 'belongsTo',
model: User
}
};
class Account {
}
Account.associations = associations;
export default Account;
import TwitterAccount from './TwitterAccount';
const associations = {
accounts: {
type: 'hasMany',
model: TwitterAccount
}
};
class User {
}
User.associations = associations;
export default User;
User.js
import User from './User';
const associations = {
user: {
type: 'belongsTo',
model: User
}
};
class Account {
}
Account.associations = associations;
export default Account;
import TwitterAccount from './TwitterAccount';
const associations = {
accounts: {
type: 'hasMany',
model: TwitterAccount
}
};
class User {
}
User.associations = associations;
export default User;
我遇到的问题是User.associations返回{accounts:{type:'hasMany',model:[Object]}}
,而Account.associations返回:{users:{type:'belongsTo',model:undefined}
现在我确实尝试了导入到
const User=require('./User')
和const Account=require('./Account')
,这解决了问题,但我不明白是什么导致了这种情况的发生?我以前从来没有遇到过这个问题 谷歌的“循环导入”。我尝试了相同的代码片段,它与“导入”工作良好。Account.associations具有未定义的用户类。你能为你的问题找个借口吗?