Meteor 1.6项目中TypeError: SimpleSchema is not a constructor问题求助
解决Meteor 1.6中SimpleSchema不是构造函数的错误
你遇到的这个错误核心原因是包的安装或导入方式不匹配,下面是具体的排查和解决步骤:
1. 确认SimpleSchema包的类型与导入方式匹配
Meteor生态里有两种常用的SimpleSchema相关包,导入方式完全不同:
Meteor官方包:
aldeed:simple-schema
如果你安装的是这个传统Meteor包,需要用Meteor专属的导入路径:import { SimpleSchema } from 'meteor/aldeed:simple-schema';安装命令:
meteor add aldeed:simple-schema独立npm包:
simpl-schema
如果你用的是这个npm包,注意它是默认导出,需要修改导入语句:import SimpleSchema from 'simpl-schema';安装命令:
npm install simpl-schema --save
2. 清理Meteor缓存并重启项目
缓存异常有时会导致模块加载失败,执行以下命令清理后重启项目:
meteor reset meteor
3. 优化Schema代码(可选)
你当前代码里createdAt和updatedAt用了String类型,其实SimpleSchema原生支持Date类型,这样更规范:
createdAt: { type: Date, label: 'The date this document was created.', autoValue() { if (this.isInsert) return new Date(); }, }, updatedAt: { type: Date, label: 'The date this document was last updated.', autoValue() { if (this.isInsert || this.isUpdate) return new Date(); }, },
按照上述步骤调整后,就能解决SimpleSchema is not a constructor的错误了。
内容的提问来源于stack exchange,提问作者amyst
相关产品推荐
相关产品推荐

