facebook/relay · error

Expected the JS type for '{}' to be defined, please update '

Error message

Expected the JS type for '{}' to be defined, please update 'customScalarTypes' in your compiler config.

What it means

For custom scalars, typegen must map the GraphQL scalar to a JS type via customScalarTypes. When the mapping is missing and the project's typegen config sets require_custom_scalar_types, the compiler panics, telling you to declare the JS type in your compiler config.

Source

Thrown at compiler/crates/relay-typegen/src/visit.rs:2353

            CustomType::Path(CustomTypeImport { name, path }) => {
                custom_scalars.insert((*name, path.clone()));

                AST::RawType(*name)
            }
        }
    } else if scalar_name.item == *TYPE_ID || scalar_name.item == *TYPE_STRING {
        AST::String
    } else if scalar_name.item == *TYPE_FLOAT || scalar_name.item == *TYPE_INT {
        AST::Number
    } else if scalar_name.item == *TYPE_BOOLEAN {
        AST::Boolean
    } else {
        if typegen_context
            .project_config
            .typegen_config
            .require_custom_scalar_types
        {
            panic!(
                "Expected the JS type for '{}' to be defined, please update 'customScalarTypes' in your compiler config.",
                scalar_name.item
            );
        }
        AST::Any
    }
}

fn transform_graphql_enum_type(
    schema: &SDLSchema,
    enum_id: EnumID,
    encountered_enums: &mut EncounteredEnums,
) -> AST {
    encountered_enums.0.insert(enum_id);
    AST::Identifier(schema.enum_(enum_id).name.item.0)
}

#[allow(clippy::too_many_arguments)]

View on GitHub (pinned to 668b1b85e0)

Solutions

  1. Add the scalar to customScalarTypes in your relay compiler config with its JS type path/export.
  2. Confirm the config key exactly matches the schema scalar name (case-sensitive).
  3. Set require_custom_scalar_types: false only as a temporary measure to fall back to Any.
  4. Regenerate with the updated config and verify all custom scalars are covered.

Example fix

// relay.config.js before
customScalarTypes: {},
// after
customScalarTypes: {
  DateTime: { path: './src/types/DateTime.ts', export: 'DateTime' },
},
Defensive patterns

Strategy: validation

Validate before calling

// ensure every schema custom scalar has a JS type mapping
for (const scalar of getCustomScalars(schema)) {
  if (!config.customScalarTypes[scalar.name]) throw new Error(`Missing customScalarTypes entry for ${scalar.name}`);
}

Type guard

const isMappedScalar = (name, cfg) => Object.prototype.hasOwnProperty.call(cfg.customScalarTypes ?? {}, name);

Prevention

When it happens

Trigger: transform_graphql_scalar_type resolves a scalar whose name is absent from the customScalarTypes mapping, with project_config.typegen_config.require_custom_scalar_types == true; triggered from transform_non_nullable_input_type / expect_scalar_type / return_ast_in_object_case.

Common situations: Adding a new custom scalar to the schema without updating customScalarTypes in relay.config; enabling require_custom_scalar_types in a project with legacy unmapped scalars; typos between the schema scalar name and the config key.

Related errors


AI-assisted analysis of facebook/relay@668b1b85e0 (2026-09-02). Data as JSON: /api/errors/31376833355369db. Report an issue: GitHub.