typeorm/typeorm · error · Error
Cannot find alias for property ${propertyPath}
Error message
Cannot find alias for property ${propertyPath} What it means
Fallback thrown by findColumnsForPropertyPath when, after walking the property path, alias is still undefined. This generally means the main alias has no metadata (no entity bound) so the relation/embedded lookups were skipped, leaving no resolvable alias. It is the terminal case when no alias could be associated with the property.
Source
Thrown at src/query-builder/QueryBuilder.ts:1386
if (!joinAttr?.alias) {
const fullRelationPath =
root.length > 0 ? `${root.join(".")}.${part}` : part
throw new Error(
`Cannot find alias for relation at ${fullRelationPath}`,
)
}
alias = joinAttr.alias
root.push(...part.split("."))
propertyPathParts.shift()
continue
}
break
}
if (!alias) {
throw new Error(`Cannot find alias for property ${propertyPath}`)
}
// Remaining parts are combined back and used to find the actual property path
const aliasPropertyPath = propertyPathParts.join(".")
const columns =
alias.metadata.findColumnsWithPropertyPath(aliasPropertyPath)
if (!columns.length) {
throw new EntityPropertyNotFoundError(propertyPath, alias.metadata)
}
return [alias, root, columns]
}
/**
* Creates a property paths for a given ObjectLiteral.
*View on GitHub (pinned to 04ff4daedc)
Solutions
- Bind an entity as the main alias: createQueryBuilder(Entity, 'alias') so metadata is available for property-path resolution.
- If querying a raw table, use raw SQL fragments in where (e.g. 'table.column = :val') instead of property-path object keys.
- Ensure the FROM clause resolves to entity metadata, not a subquery string.
Example fix
// before
const qb = dataSource.createQueryBuilder()
.from('users', 'u')
.where({ 'profile.city': 'NYC' }); // 484: no metadata
// after
const qb = dataSource.createQueryBuilder(User, 'u')
.leftJoin('u.profile', 'profile')
.where('profile.city = :city', { city: 'NYC' }); Defensive patterns
Strategy: validation
Validate before calling
function assertHasEntityMainAlias(qb) {
const a = qb.expressionMap.mainAlias;
if (!a || !a.hasMetadata) throw new Error('QueryBuilder needs an entity main alias for property paths');
} Type guard
function hasEntityMainAlias(qb): boolean {
const a = qb.expressionMap.mainAlias;
return !!a && !!a.hasMetadata;
} Prevention
- Start builders from an entity: createQueryBuilder(Entity, 'alias').
- Use raw SQL where() fragments for raw-table queries instead of property-path keys.
- Avoid mixing raw FROM with entity-style property paths.
When it happens
Trigger: You build a query builder from a raw table or subquery string (no entity metadata), e.g. createQueryBuilder().select(...).where({ 'some.column': 1 }), then reference a dotted property path. The main alias lacks metadata so the loop breaks immediately and alias stays undefined.
Common situations: Using createQueryBuilder with a raw table name instead of an entity. Calling where/addMapping on a query whose FROM is a subquery. Mixing entity-style property paths with raw-table builders.
Related errors
- Cannot find alias for relation at ${fullRelationPath}
- Cannot get entity metadata for the given alias "${this.name}
- Main alias is not set
- Property "${propertyPath}" was not found in "${metadata.targ
- "${aliasName}" alias was not found. Maybe you forgot to join
AI-assisted analysis of typeorm/typeorm@04ff4daedc (2026-08-03).
Data as JSON: /data/errors/258d3cbbe13ecb9d.json.
Report an issue: GitHub.