Making SimpleSchema global again

Up until now, I’ve been doing:


in a local package to make sure that aldeed:collection2 and aldeed:simple-schema are available to the app. (SimpleSchema is a global in all files. I’m using the old directory structures without imports.)

If I change this to:


(I know the imply line is now irrelevant in this scenario.)

and then:

meteor npm install --save simpl-schema

then, when trying to start the app, I get:

ReferenceError: SimpleSchema is not defined

for files used in the same local package. (i.e. later in the local package’s package.json file, there are things like: api.addFiles('collections/groups.js'); and in that file SimpleSchema is being used as if it’s globally available.)

Is there an easy way to make SimpleSchema a global while using aldeed:collection2@3.0.0?

(Github issue here if this is the wrong place for this question.)

Have you tried importing it and just setting a regular global, like this:

import SimpleSchema from 'simpl-schema';
window.SimpleSchema = SimpleSchema;

(and on server side global.SimpleSchema = SimpleSchema)

Disclaimer: I’ve never worked with the simpl-schema npm package yet.


I did try importing (import SimpleSchema from 'simpl-schema';) with exactly that in mind, but it was throwing some error on the server at startup about the import symbol not being recognized. Does the above have to be done within the imports directory?

You have to do an intermediary import/export file. The import as it is does not make the class global. So import simpleschema into another file, then export it under another name (‘mySS’ for eg). THEN import your custom convention for simple schema and attach THAT to the global namespace as SimpleSchema (SimpleSchema = mySS).

BTW, I do that in my own prototyping boilerplate here:

1 Like

Oh cool. I get it. That boilerplate was very instructive. Thank you!

1 Like

Thanks! Glad it helped.

You can include the npm package in your local meteor package:

  'simpl-schema': '1.4.2'
1 Like

I tried that, but SimpleSchema still isn’t available as a global to the other files added later in the package.json. You still have to do the little import/export trick that @rd010 describes above.

1 Like