emberjs/ember.js · error · Error

Could not create factory

Error message

Could not create factory

What it means

instantiateFactory reached its fall-through with no branch able to produce a value: the fullName resolved to something that is neither a singleton/class factory case the container understands. This usually means an invalid registration state rather than user input.

Source

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

    }

    return instance;
  }

  // SomeClass { singleton: false, instantiate: true }
  if (isFactoryInstance(container, fullName, options)) {
    return factoryManager.create();
  }

  // SomeClass { singleton: true, instantiate: false } | { instantiate: false } | { singleton: false, instantiation: false }
  if (
    isSingletonClass(container, fullName, options) ||
    isFactoryClass(container, fullName, options)
  ) {
    return factoryManager.class;
  }

  throw new Error('Could not create factory');
}

function destroyDestroyables(container: Container): void {
  let cache = container.cache;
  let keys = Object.keys(cache);

  for (let key of keys) {
    let value = cache[key];
    assert('has cached value', value);

    if ((value as any).destroy) {
      (value as any).destroy();
    }
  }
}

function resetCache(container: Container) {
  container.cache = dictionary(null);

View on GitHub (pinned to 26f97246a8)

Solutions

  1. Use standard registration/lookup patterns (register + lookup with default options)
  2. Check the options passed to lookup/register for stray { instantiate: false }
  3. Verify the fullName is properly registered and normalized
  4. Upgrade ember-source — internal factory handling has changed over versions
Defensive patterns

Strategy: validation

Validate before calling

if (!owner.hasRegistration(fullName)) throw new Error(`Not registered: ${fullName}`);

Type guard

function isRegistrableName(n) { return typeof n === 'string' && n.includes(':'); }

Try / catch

try { return owner.lookup(fullName, opts); } catch (e) { if (e.message === 'Could not create factory') { /* fix registration/options */ } throw e; }

Prevention

When it happens

Trigger: lookup() on a name whose cached/factory state matches none of the recognized shapes (not a singleton instance, not a singleton class, not a factory class) — typically from an unusual custom RegisterOptions combination or corrupted cache.

Common situations: Custom container/registry experimentation; options like { instantiate: false } combined unexpectedly with singleton/factory class registrations; internal misuse from engines or custom resolvers.

Related errors


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