问题
My app constantly crashes with this error. TypeError: SimpleSchema is not a constructor at attendances.js (imports/api/attendances/attendances.js:44:27)
. I've googled it and the StackOverflow solution doesn't work. I'm running simpl-schema and Collection2 Can anyone tell me whats wrong here?
import { Mongo } from 'meteor/mongo';
import SimpleSchema from 'simpl-schema';
const Attendances = new Mongo.Collection('attendances');
Attendances.debug = true;
Attendances.allow({
insert: () => true,
update: () => true,
remove: () => true,
});
Attendances.deny({
insert: () => false,
update: () => false,
remove: () => false,
});
const AttendancesSchema = new SimpleSchema({
createdAt: {
type: Date,
},
}, {
clean: {
filter: true,
autoConvert: true,
removeEmptyStrings: true,
trimStrings: true,
getAutoValues: true,
},
});
Attendances.attachSchema(AttendancesSchema);
export default Attendances;
This is the full error message in my terminal.
Path: ERROR MESSAGE
W20180620-21:07:11.542(10)? (STDERR) TypeError: SimpleSchema is not a constructor
W20180620-21:07:11.542(10)? (STDERR) at attendances.js (imports/api/attendances/attendances.js:44:27)
W20180620-21:07:11.543(10)? (STDERR) at fileEvaluate (packages/modules-runtime.js:339:7)
W20180620-21:07:11.543(10)? (STDERR) at require (packages/modules-runtime.js:238:16)
W20180620-21:07:11.543(10)? (STDERR) at publications.js (imports/api/userProfiles/server/publications.js:1:354)
W20180620-21:07:11.543(10)? (STDERR) at fileEvaluate (packages/modules-runtime.js:339:7)
W20180620-21:07:11.543(10)? (STDERR) at require (packages/modules-runtime.js:238:16)
W20180620-21:07:11.543(10)? (STDERR) at register-api.js (imports/startup/server/register-api.js:1:195)
W20180620-21:07:11.543(10)? (STDERR) at fileEvaluate (packages/modules-runtime.js:339:7)
W20180620-21:07:11.544(10)? (STDERR) at require (packages/modules-runtime.js:238:16)
W20180620-21:07:11.544(10)? (STDERR) at index.js (imports/startup/server/index.js:1:50)
W20180620-21:07:11.544(10)? (STDERR) at fileEvaluate (packages/modules-runtime.js:339:7)
W20180620-21:07:11.544(10)? (STDERR) at require (packages/modules-runtime.js:238:16)
W20180620-21:07:11.544(10)? (STDERR) at main.js (server/main.js:1:14)
W20180620-21:07:11.544(10)? (STDERR) at fileEvaluate (packages/modules-runtime.js:339:7)
W20180620-21:07:11.545(10)? (STDERR) at require (packages/modules-runtime.js:238:16)
W20180620-21:07:11.545(10)? (STDERR) at /Users/blakepascoe/Documents/dev/roll_call/.meteor/local/build/programs/server/app/app.js:1725:1
回答1:
I tried the suggested fix in the comment by @bp123 that you should reset the Meteor project, and that fixed it for me too.
So I'm turning that comment into an answer:
Reset your project.
It does not seem impossible that a schema need to be added before any data is put in the database, but I'm very confused why this applies even for creating a Schema without attaching it to anything.
来源:https://stackoverflow.com/questions/50946918/simpleschema-is-not-a-constructor