jquense/yup · error · Error

The schema does not contain the path: ${path}. (failed at: $

Error message

The schema does not contain the path: ${path}. (failed at: ${lastPartDebug} which is a type: "${schema.type}")

What it means

When a path part is not an array index, getIn() looks it up in schema.fields. This Error is thrown when the current schema has no field matching that part, meaning the path does not exist in the schema. The message includes the failing part and the schema's type for debugging.

Source

Thrown at src/util/reach.ts:51

        );
      if (value && idx >= value.length) {
        throw new Error(
          `Yup.reach cannot resolve an array item at index: ${_part}, in the path: ${path}. ` +
            `because there is no value at that index. `,
        );
      }
      parent = value;
      value = value && value[idx];
      schema = isTuple ? schema.spec.types[idx] : schema.innerType!;
    }

    // sometimes the array index part of a path doesn't exist: "nested.arr.child"
    // in these cases the current part is the next schema and should be processed
    // in this iteration. For cases where the index signature is included this
    // check will fail and we'll handle the `child` part on the next iteration like normal
    if (!isArray) {
      if (!schema.fields || !schema.fields[part])
        throw new Error(
          `The schema does not contain the path: ${path}. ` +
            `(failed at: ${lastPartDebug} which is a type: "${schema.type}")`,
        );

      parent = value;
      value = value && value[part];
      schema = schema.fields[part];
    }

    lastPart = part;
    lastPartDebug = isBracket ? '[' + _part + ']' : '.' + _part;
  });

  return { schema, parent, parentPath: lastPart! };
}

function reach<P extends string, S extends ISchema<any>>(
  obj: S,

View on GitHub (pinned to ff31eee8a2)

Solutions

  1. Fix the path to match an existing schema field (check spelling/case)
  2. Verify the path against the schema definition before calling reach
  3. For dynamic paths, validate the part against Object.keys(schema.fields)
  4. If using noUnknown/cast flows, derive paths from the data's own shape carefully

Example fix

// before
yup.reach(userSchema, 'emial');
// after
yup.reach(userSchema, 'email');
Defensive patterns

Strategy: validation

Validate before calling

function schemaHasPath(schema: yup.AnyObjectSchema, path: string): boolean {
  return path.split('.').every((part, i, parts) => {
    const fields = (schema as any).fields ?? {};
    if (!(part in fields)) return false;
    schema = fields[part];
    return true;
  });
}

Type guard

function fieldExists(schema: any, part: string): boolean {
  return !!schema?.fields && Object.prototype.hasOwnProperty.call(schema.fields, part);
}

Try / catch

try { return yup.reach(schema, path); } catch (e) { if (/does not contain the path/.test(e.message)) return null; throw e; }

Prevention

When it happens

Trigger: yup.reach(objectSchema, 'wrongField'), a typo in the path, or reaching into a schema whose type doesn't support fields (e.g. a string) at that position.

Common situations: Renamed object keys without updating path strings; paths written for a different schema version; dynamic paths built from user input that doesn't match the schema shape.

Related errors


AI-assisted analysis of jquense/yup@ff31eee8a2 (2026-08-31). Data as JSON: /api/errors/c58572cc4ead9bd5. Report an issue: GitHub.