{"record":{"id":"2c6b6f6c6a2fed49","repo":"Automattic/mongoose","slug":"invalid-schema-configuration-name-is-not-a-v","errorCode":null,"errorMessage":"Invalid schema configuration: `${name}` is not a valid type at path `${path}`. See https://bit.ly/mongoose-schematypes for a list of valid schema types.","messagePattern":"Invalid schema configuration: `(.+?)` is not a valid type at path `(.+?)`\\. See https://bit\\.ly/mongoose-schematypes for a list of valid schema types\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"lib/schema.js","lineNumber":1797,"sourceCode":"    name = name.charAt(0).toUpperCase() + name.substring(1);\n  }\n  // Special case re: gh-7049 because the bson `ObjectID` class' capitalization\n  // doesn't line up with Mongoose's.\n  if (name === 'ObjectID') {\n    name = 'ObjectId';\n  }\n  // For Jest 26+, see #10296\n  if (name === 'ClockDate') {\n    name = 'Date';\n  }\n\n  if (name === void 0) {\n    throw new TypeError(`Invalid schema configuration: \\`${path}\\` schematype definition is ` +\n      'invalid. See ' +\n      'https://mongoosejs.com/docs/guide.html#definition for more info on supported schema syntaxes.');\n  }\n  if (MongooseTypes[name] == null) {\n    throw new TypeError(`Invalid schema configuration: \\`${name}\\` is not ` +\n      `a valid type at path \\`${path}\\`. See ` +\n      'https://bit.ly/mongoose-schematypes for a list of valid schema types.');\n  }\n\n  const schemaType = new MongooseTypes[name](path, obj, options, this);\n\n  return schemaType;\n};\n\n/**\n * Iterates the schemas paths similar to Array#forEach.\n *\n * The callback is passed the pathname and the schemaType instance.\n *\n * #### Example:\n *\n *     const userSchema = new Schema({ name: String, registeredAt: Date });\n *     userSchema.eachPath((pathname, schematype) => {","sourceCodeStart":1779,"sourceCodeEnd":1815,"githubUrl":"https://github.com/Automattic/mongoose/blob/49cdab01366679723b487ecb754b38570f783289/lib/schema.js#L1779-L1815","documentation":"Mongoose resolves every schema path definition to a SchemaType class by looking the type's constructor name up in its registry (Schema.Types / MongooseTypes). This error means the name resolved for `path` has no registered SchemaType, so the path cannot be represented and the schema build fails immediately rather than producing a silently unusable path.","triggerScenarios":"A path whose `type` is unregistered: `{ type: undefined }` caused by a circular import or wrong default/named import, a typo like `{ type: Strring }`, a project class never registered with mongoose, or referencing a type your mongoose version does not ship (e.g. BigInt/UUID on old versions). Also `new Schema({ x: MyUnregisteredClass })` directly.","commonSituations":"Circular requires between schema modules that leave an imported type undefined at definition time; TypeScript/ESM interop mixing default and named imports; downgrading mongoose and losing newer types; copy-pasted schemas referencing classes from another package.","solutions":["Log the imported symbol before `new Schema(...)` - `undefined` almost always means a circular import or the wrong import form (default vs named).","Spell built-ins exactly: String, Number, Date, Boolean, Buffer, Map, Mixed, ObjectId, BigInt, UUID, or mongoose.Schema.Types.X.","Register custom SchemaTypes before use: mongoose.Schema.Types.MyType = MySchemaType (or use an established mongoose-type package).","Upgrade to a mongoose version that ships the type you reference (BigInt needs >= 6.x, UUID needs >= 6.10).","Use Schema.Types.Mixed for genuinely arbitrary payloads instead of an unregistered class."],"exampleFix":"// before\nclass EmailType extends mongoose.SchemaType {}\n// circular require leaves EmailType undefined at schema-definition time:\nmodule.exports = { schema: new Schema({ contact: { type: require('./email').EmailType } }) };\n\n// after\nconst { EmailType } = require('./email'); // import once the module graph resolves\nmongoose.Schema.Types.Email = EmailType; // register once at bootstrap\nconst s = new Schema({ contact: EmailType });","handlingStrategy":"validation","validationCode":"const assertValidTypes = (def) => {\n  for (const [path, opts] of Object.entries(def)) {\n    const t = opts && opts.type ? opts.type : opts;\n    if (typeof t !== 'function') continue; // nested pojo\n    if (mongoose.Schema.Types[t.name] == null) {\n      throw new Error(`path ${path}: type ${t.name} is not a registered SchemaType`);\n    }\n  }\n};\nassertValidTypes(myDefinition);\nconst schema = new Schema(myDefinition);","typeGuard":"const isRegisteredSchemaType = (t) =>\n  typeof t === 'function' &&\n  mongoose.Schema.Types[t.name] != null;","tryCatchPattern":"try { new Schema(def); } catch (err) { if (err instanceof TypeError && err.message.includes('not a valid type')) { /* log the definition and imported symbols, fail startup */ } throw err; }","preventionTips":["Ban import cycles (eslint-plugin-import no-cycle) - the top cause of undefined types in schemas.","Construct all schemas at module load so type errors crash CI instead of the first request.","Centralize custom type registration (mongoose.Schema.Types.X = ...) in one bootstrap module."],"tags":["schema","type-resolution","configuration","circular-imports"],"backgroundTag":"invalid-schema-type","analyzedSha":"49cdab01366679723b487ecb754b38570f783289","analyzedAt":"2026-08-21T22:54:00.882Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}