emberjs/ember.js · error · Error

Cannot call `.factoryFor('${fullName}')` after the owner has

Error message

Cannot call `.factoryFor('${fullName}')` after the owner has been destroyed

What it means

Container#factoryFor refuses to return a factory manager after the owner has been destroyed. Like lookup, factory resolution is invalid post-teardown; Ember throws to surface lifecycle bugs rather than hand back unusable factories.

Source

Thrown at packages/@ember/-internals/container/lib/container.ts:223

  ownerInjection() {
    let injection = {};
    setOwner(injection, this.owner!);
    return injection;
  }

  /**
   Given a fullName, return the corresponding factory. The consumer of the factory
   is responsible for the destruction of any factory instances, as there is no
   way for the container to ensure instances are destroyed when it itself is
   destroyed.
    @public
   @method factoryFor
   @param {String} fullName
   @return {any}
   */
  factoryFor(fullName: FullName): InternalFactoryManager<object> | undefined {
    if (this.isDestroyed) {
      throw new Error(
        `Cannot call \`.factoryFor('${fullName}')\` after the owner has been destroyed`
      );
    }
    let normalizedName = this.registry.normalize(fullName);

    assert('fullName must be a proper full name', this.registry.isValidFullName(normalizedName));

    return factoryFor(this, normalizedName, fullName);
  }
}

if (DEBUG) {
  Container._leakTracking = leakTracking!;
}

/*
 * Wrap a factory manager in a proxy which will not permit properties to be
 * set on the manager.

View on GitHub (pinned to 26f97246a8)

Solutions

  1. Cancel/complete pending async work before the owner is destroyed
  2. Guard calls with isDestroying/isDestroyed checks on the owner
  3. Move factory resolution earlier in the lifecycle (before teardown begins)
  4. In tests, ensure settled() before teardown

Example fix

// before
let Factory = owner.factoryFor('model:user').class;
// after
if (!owner.isDestroyed) {
  let Factory = owner.factoryFor('model:user').class;
}
Defensive patterns

Strategy: validation

Validate before calling

if (owner.isDestroyed) return; let mgr = owner.factoryFor('service:foo');

Type guard

function canFactoryFor(owner) { return Boolean(owner) && !owner.isDestroyed && !owner.isDestroying; }

Try / catch

try { return owner.factoryFor(fullName); } catch (e) { if (String(e.message).includes('factoryFor') && e.message.includes('destroyed')) return undefined; throw e; }

Prevention

When it happens

Trigger: Calling owner.factoryFor('service:foo') after owner.destroy() — commonly in deferred async code, leftover observers, or during test teardown.

Common situations: Test teardown racing with pending promises; code caching an owner and using it after app destroy; engine teardown while child components still resolve factories.

Related errors


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