n8n-io/n8n · error · TreeRepositoryNotSupportedError
Tree repositories are not supported in ${driver.options.type
Error message
Tree repositories are not supported in ${driver.options.type} driver. What it means
EntityManager.getTreeRepository checks the active driver's `treeSupport` flag (false for MongoDB and any driver without closure-table / nested-set support). When treeSupport is false, it throws TreeRepositoryNotSupportedError naming the driver type. Tree repositories require SQL features (CTEs/closure tables) that some drivers cannot provide.
Source
Thrown at packages/@n8n/typeorm/src/entity-manager/EntityManager.ts:1254
// if repository was not found then create it, store its instance and return it
const newRepository = new Repository<any>(target, this, this.queryRunner);
this.repositories.set(target, newRepository);
return newRepository;
}
/**
* Gets tree repository for the given entity class or name.
* If single database connection mode is used, then repository is obtained from the
* repository aggregator, where each repository is individually created for this entity manager.
* When single database connection is not used, repository is being obtained from the connection.
*/
getTreeRepository<Entity extends ObjectLiteral>(
target: EntityTarget<Entity>,
): TreeRepository<Entity> {
// tree tables aren't supported by some drivers (mongodb)
if (this.connection.driver.treeSupport === false)
throw new TreeRepositoryNotSupportedError(this.connection.driver);
// find already created repository instance and return it if found
const repository = this.treeRepositories.find((repository) => repository.target === target);
if (repository) return repository;
// check if repository is real tree repository
const newRepository = new TreeRepository(target, this, this.queryRunner);
this.treeRepositories.push(newRepository);
return newRepository;
}
/**
* Creates a new repository instance out of a given Repository and
* sets current EntityManager instance to it. Used to work with custom repositories
* in transactions.
*/
withRepository<Entity extends ObjectLiteral, R extends Repository<any>>(
repository: R & Repository<Entity>,View on GitHub (pinned to 5ac6606e81)
Solutions
- Use a tree-supporting driver (Postgres, MySQL, SQLite, MSSQL) for entities decorated with @Tree/@TreeChildren/@TreeParent.
- If you must stay on MongoDB, model the hierarchy manually (parent references + recursive aggregation) and stop using the TreeRepository API.
- Audit `@Tree(` decorators across the codebase before changing the configured driver.
Example fix
// before - tree entity used against MongoDB
@Entity()
@Tree('closure-table')
class Category { @TreeChildren() children?: Category[]; }
// DataSource type: 'mongodb'
// after - use Postgres, or drop tree decorators on Mongo
// Option A: switch datasource to a tree-supporting driver
const ds = new DataSource({ type: 'postgres', ... });
// Option B: keep Mongo, remove @Tree and model parent refs manually Defensive patterns
Strategy: validation
Validate before calling
function assertTreeSupported(driver: import('@n8n/typeorm').Driver): void {
if ((driver as any).treeSupport === false) {
throw new Error(`Driver ${driver.options.type} does not support tree repositories`);
}
}
assertTreeSupported(connection.driver);
await manager.getTreeRepository(Category); Type guard
function driverSupportsTrees(driver: import('@n8n/typeorm').Driver): boolean {
return (driver as any).treeSupport !== false;
} Prevention
- Do not use @Tree/@TreeChildren/@TreeParent on MongoDB entities.
- Before switching DB engines, grep for @Tree decorators.
- Model hierarchies manually (parent FK + recursive query) on non-tree drivers.
- Keep tree-decorated entities in their own connection if multi-DB.
When it happens
Trigger: Configuring a @TreeParen/TreeChildren/TreeLevelColumn entity against MongoDB; calling `manager.getTreeRepository(Category)` while connected to a non-tree-supporting driver; mixing a tree-decorated entity into a multi-DB project where one connection is MongoDB; migrating from SQL to Mongo without removing tree decorators.
Common situations: Switching DB engines without auditing entity decorators; copy-pasting a tree-structured entity from a SQL project into a Mongo project; testing against Mongo while production runs on Postgres.
Related errors
- Cannot attach entity "${entityName}" to its parent. Please m
- Nested sets do not support multiple root entities.
- Cannot save user <${this.email}>: Provided email is invalid
- Wrong driver: "${driverType}" given. Supported drivers are:
- Driver not Connected
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/84af38ced2ba3aef.
Report an issue: GitHub.