下一页 JS 猫鼬模式"无法读取未定义的属性"



我有NextJS项目与猫鼬模式里面。我一直在开发环境中得到以下错误:

TypeError: Cannot read properties of undefined (reading 'Village')

我的模型文件是:
import mongoose from "mongoose";
const {Schema} = mongoose;
const VillageSchema = new mongoose.Schema(
{
id: {type: String},
...
);
// prettier-ignore
export default mongoose.models.Village || mongoose.model("Village", VillageSchema);

尝试为导出值添加可选链接:

// prettier-ignore
export default mongoose.models?.Village || mongoose.model("Village", VillageSchema);

相关内容

  • 没有找到相关文章