emberjs/ember.js · error · Error

Defining a custom serialize method on an Engine route is not

Error message

Defining a custom serialize method on an Engine route is not supported.

What it means

When the router resolves a route that belongs to an engine (route has engineInfo), the route must use the engine's default serialization. A custom serialize method defined on an Engine route conflicts with how engine routes serialize their models, so Router#getRoute throws.

Source

Thrown at packages/@ember/routing/router.ts:421

        if (!route) {
          // SAFETY: this is configured in `commonSetupRegistry` in the
          // `@ember/application/lib` package.
          let DefaultRoute: any = routeOwner.factoryFor('route:basic')!.class;
          routeOwner.register(fullRouteName, class extends DefaultRoute {});
          route = routeOwner.lookup(fullRouteName) as Route;

          if (DEBUG) {
            if (router.namespace.LOG_ACTIVE_GENERATION) {
              info(`generated -> ${fullRouteName}`, { fullName: fullRouteName });
            }
          }
        }

        route._setRouteName(routeName);

        if (engineInfo && !hasDefaultSerialize(route)) {
          throw new Error(
            'Defining a custom serialize method on an Engine route is not supported.'
          );
        }

        return route;
      }

      getSerializer(name: string) {
        let engineInfo = router._engineInfoByRoute[name];

        // If this is not an Engine route, we fall back to the handler for serialization
        if (!engineInfo) {
          return;
        }

        return engineInfo.serializeMethod || defaultSerialize;
      }

View on GitHub (pinned to 26f97246a8)

Solutions

  1. Remove the custom serialize method from the engine route
  2. Handle serialization in the parent app's route that mounts the engine
  3. Use the default dynamic segment serialization expected by the engine's route map

Example fix

// before (engine route)
export default class PostRoute extends Route {
  serialize(model) { return { slug: model.slug }; }
}
// after
export default class PostRoute extends Route {} // rely on default serialize / parent route
Defensive patterns

Strategy: validation

Validate before calling

if (routeInfo.engineInfo && typeof route.serialize === 'function' && !hasDefaultSerialize(route)) {
  throw new Error('Engine routes cannot define custom serialize');
}

Type guard

function isEngineRouteWithoutCustomSerialize(route) { return !route.serialize || route.serialize === Route.prototype.serialize; }

Try / catch

try { route = router.getRoute(name); } catch (e) { if (/custom serialize method on an Engine route/.test(e.message)) { route = getRouteWithoutSerialize(name); } else throw e; }

Prevention

When it happens

Trigger: Defining serialize(model) in an engine's route class (or serializeMethod) and then navigating/looking up that route through getRoute when engineInfo is present and hasDefaultSerialize(route) is false.

Common situations: Migrating a standard route with a custom serialize hook into an engine; addons that add serialize hooks to routes that later get mounted inside engines.

Related errors


AI-assisted analysis of emberjs/ember.js@26f97246a8 (2026-09-01). Data as JSON: /api/errors/94a8efc1299fc6a6. Report an issue: GitHub.