I have a massive headache to share some common schema definitions with a module to all other modules in my code base.
I have a module myproj_schemas that contains these two schemes:
var mongoose = require('mongoose'), util = require("util"), Schema = mongoose.Schema; var BaseProfileSchema = function() { Schema.apply(this, arguments); this.add({ _user: {type: Schema.Types.ObjectId, ref: 'User', required: true}, name: {type: String, required: true}, bio: {type: String, required: true}, pictureLink: String }); }; util.inherits(BaseProfileSchema, Schema); module.exports = BaseProfileSchema;
and
var mongoose = require('mongoose'), BaseProfileSchema = require('./base_profile_schema.js'), Schema = mongoose.Schema; var entSchemaAdditions = { mentors: {type: Schema.Types.ObjectId, ref: 'Mentor'} }; var entrepreneurSchema = new BaseProfileSchema(entSchemaAdditions); module.exports = entrepreneurSchema;
Mentors are also defined in another file.
My unit tests for both of these work in the circuit module.
When I install this module and try to create using
Entrepreneur = db.model('Entrepreneur', entrepreneurSchema),
I get the following error:
TypeError: Undefined enter paths.mentors Have you tried paths.mentors schema? You can only embed with links or arrays.
If I use the same code in my local module, then there is no problem. If I refer to the schema file directly in require (for example, require ('../node_modules/myproj_schemas/models/ent_schema'), then I get an error.
I am sure that this did not break before, but I canceled all the changes and still does not work.
I draw a complete space, and any suggestions would be greatly appreciated.
EDIT:
I created a new Schemas module. It has one circuit:
var mongoose = require('mongoose'); var userSchema = new mongoose.Schema({ email: String }); module.exports = userSchema;
It also fails to pack in a module and npm install'd to other modules.
Work on OS X