1

When using simpl-schema I am getting the following error:

SimpleSchema is not a constructor

I have already added

aldeed:autoform
aldeed:collection2@3.0.0
"simpl-schema": "^1.4.3"

My code:

import { Mongo } from 'meteor/mongo';    
import  SimpleSchema  from 'simpl-schema';     
export const Books = new Mongo.Collection("books");     
const Book = new SimpleSchema({
    title: {
        type: String,
        label: "Title",
        max: 200
    },
    author: {
        type: String,
        label: "Author"
    },
    copies: {
        type: SimpleSchema.Integer,
        label: "Number of copies",
        min: 0
    },
    lastCheckedOut: {
        type: Date,
        label: "Last date this book was checked out",
        optional: true
    },
    summary: {
        type: String,
        label: "Brief summary",
        optional: true,
        max: 1000,
        optional: true
    }
});
Books.attachSchema(Book);

What's causing it and how can I fix it?

MasterAM
  • 16,283
  • 6
  • 45
  • 66
Nimmi Verma
  • 465
  • 6
  • 11
  • Everything seems correct, just the "simpl-schema": "^1.4.3" should be aldeed:simpl-schema in your .meteor/packages file – Amar Pathak Jun 26 '18 at 16:24
  • At first I added that package. It didn't workout. – Nimmi Verma Jun 27 '18 at 05:23
  • @AmarPathak, `aldeed:simpl-schema` is deprecated and _does not_ work with `collection2@3.0.0`. @NimmiVerma have you checked that `simple-schema` exists in `/node_modules/simpl-schema`? maybe delete `node_modules` and re-install? – coagmano Jun 27 '18 at 07:00
  • The most common cause of these errors are either a typo in the import statement or failed npm install – coagmano Jun 27 '18 at 07:02
  • I have this too. And yes, `node_modules/simpl-schema` contains SimpleSchema.js. Some other package I used returned undefined for its exports in insecure mode, because it was only designed to work on the server. Could that be it? – thoni56 Sep 30 '18 at 14:41
  • There is one answer at https://stackoverflow.com/a/52579056/204658. – thoni56 Sep 30 '18 at 14:58

0 Answers0