emberjs/ember.js · error · Error
Cannot create new instances after the owner has been destroy
Error message
Cannot create new instances after the owner has been destroyed (you attempted to create ${this.fullName}) What it means
FactoryManager#create refuses to instantiate new objects once the owning container is destroyed. Even though a factory reference may survive teardown, creating instances from it would produce objects bound to a dead owner.
Source
Thrown at packages/@ember/-internals/container/lib/container.ts:535
this.fullName = fullName;
this.normalizedName = normalizedName;
this.madeToString = undefined;
this.injections = undefined;
}
toString(): string {
if (this.madeToString === undefined) {
this.madeToString = this.container.registry.makeToString(this.class, this.fullName);
}
return this.madeToString;
}
create(options?: Partial<T>) {
let { container } = this;
if (container.isDestroyed) {
throw new Error(
`Cannot create new instances after the owner has been destroyed (you attempted to create ${this.fullName})`
);
}
let props = options ? { ...options } : {};
setOwner(props, container.owner!);
setFactoryFor(props, this);
if (DEBUG) {
let lazyInjections;
let validationCache = this.container.validationCache;
// Ensure that all lazy injections are valid at instantiation time
if (
!validationCache[this.fullName] &&
this.class &&
typeof this.class._lazyInjections === 'function'
) {
lazyInjections = this.class._lazyInjections();View on GitHub (pinned to 26f97246a8)
Solutions
- Create instances before teardown or guard with container/owner isDestroyed checks
- Cancel pending async work in willDestroy
- In tests, await settled() before teardown
- Rearchitect to get instances injected rather than created imperatively later
Example fix
// before
later = run.later(() => this.store.createRecord('user'), 1000);
// after
later = run.later(() => {
if (!this.isDestroying) this.store.createRecord('user');
}, 1000); Defensive patterns
Strategy: validation
Validate before calling
if (this.isDestroying || this.isDestroyed) return; let obj = Factory.create(props);
Type guard
function canCreate(owner) { return !owner.isDestroyed && !owner.isDestroying; } Try / catch
try { return Factory.create(props); } catch (e) { if (String(e.message).includes('Cannot create new instances after the owner has been destroyed')) return null; throw e; } Prevention
- Create instances during normal lifecycle, not post-teardown
- Cancel deferred work in willDestroy
- Prefer injection over imperative create()
- Use settled() in tests before teardown
When it happens
Trigger: Calling factoryFor(...).create() after the owner was destroyed — typically in async callbacks, Ember.run.later callbacks, or retained references used post-teardown.
Common situations: Retaining a factory manager and creating records/services after test teardown; fastboot shutdown mid-request; app.destroy() while background sync code still creates objects.
Related errors
- Cannot call `.lookup('${fullName}')` after the owner has bee
- Cannot call `.factoryFor('${fullName}')` after the owner has
- You attempted to set "${String(prop)}" on a factory manager
- Could not create factory
- The API deprecated by ${options.id} was removed in ember-sou
AI-assisted analysis of emberjs/ember.js@26f97246a8 (2026-09-01).
Data as JSON: /api/errors/753454619d38129c.
Report an issue: GitHub.