Automattic/mongoose · error · TypeError

Invalid schema configuration: `${val}` is not a valid type a

Error message

Invalid schema configuration: `${val}` is not a valid type at path `${key}`. See https://bit.ly/mongoose-schematypes for a list of valid schema types.

What it means

Error "Invalid schema configuration: `${val}` is not a valid type at path `${key}`. See https://bit.ly/mongoose-schematypes for a list of valid schema types." thrown in Automattic/mongoose.

Source

Thrown at lib/schema.js:831

    }
    // Retain `_id: false` but don't set it as a path, re: gh-8274.
    if (key === '_id' && val === false) {
      continue;
    }
    // Deprecate setting schema paths to primitive types (gh-7558)
    let isMongooseTypeString = false;
    if (typeof val === 'string') {
      // Handle the case in which the type is specified as a string (eg. 'date', 'oid', ...)
      const MongooseTypes = this.base?.Schema.Types ?? Schema.Types;
      const upperVal = val.charAt(0).toUpperCase() + val.substring(1);
      isMongooseTypeString = MongooseTypes[upperVal] != null;
    }
    if (
      key !== '_id' &&
      ((typeof val !== 'object' && typeof val !== 'function' && !isMongooseTypeString) ||
      val == null)
    ) {
      throw new TypeError(`Invalid schema configuration: \`${val}\` is not ` +
        `a valid type at path \`${key}\`. See ` +
        'https://bit.ly/mongoose-schematypes for a list of valid schema types.');
    }
    if (val instanceof VirtualType || (val.constructor?.name ?? null) === 'VirtualType') {
      this.virtual(val);
      continue;
    }

    if (Array.isArray(val) && val.length === 1 && val[0] == null) {
      throw new TypeError('Invalid value for schema Array path `' + fullPath +
        '`, got value "' + val[0] + '"');
    }

    if (!(isPOJO(val) || val instanceof SchemaTypeOptions)) {
      // Special-case: Non-options definitely a path so leaf at this node
      // Examples: Schema instances, SchemaType instances
      if (prefix) {
        this.nested[prefix.substring(0, prefix.length - 1)] = true;

View on GitHub (pinned to 49cdab0136)

When it happens

Trigger: Thrown at lib/schema.js:831 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Automattic/mongoose@49cdab0136 (2026-08-21). Data as JSON: /api/errors/444c3b95114cbc2b. Report an issue: GitHub.