{"record":{"id":"5cf321e0f3cb2eb0","repo":"n8n-io/n8n","slug":"custom-repository-repository-name-was-not-found","errorCode":null,"errorMessage":"Custom repository ${repository.name} was not found. Did you forgot to put @EntityRepository decorator on it?","messagePattern":"Custom repository (.+?) was not found\\. Did you forgot to put @EntityRepository decorator on it\\?","errorType":"exception","errorClass":"CustomRepositoryNotFoundError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/typeorm/src/entity-manager/EntityManager.ts","lineNumber":1297,"sourceCode":"\t}\n\n\t/**\n\t * Gets custom entity repository marked with @EntityRepository decorator.\n\t *\n\t * @deprecated use Repository.extend to create custom repositories\n\t */\n\tgetCustomRepository<T>(customRepository: ObjectType<T>): T {\n\t\tconst entityRepositoryMetadataArgs = getMetadataArgsStorage().entityRepositories.find(\n\t\t\t(repository) => {\n\t\t\t\treturn (\n\t\t\t\t\trepository.target ===\n\t\t\t\t\t(typeof customRepository === 'function'\n\t\t\t\t\t\t? customRepository\n\t\t\t\t\t\t: (customRepository as any).constructor)\n\t\t\t\t);\n\t\t\t},\n\t\t);\n\t\tif (!entityRepositoryMetadataArgs) throw new CustomRepositoryNotFoundError(customRepository);\n\n\t\tconst entityMetadata = entityRepositoryMetadataArgs.entity\n\t\t\t? this.connection.getMetadata(entityRepositoryMetadataArgs.entity)\n\t\t\t: undefined;\n\t\tconst entityRepositoryInstance = new (entityRepositoryMetadataArgs.target as any)(\n\t\t\tthis,\n\t\t\tentityMetadata,\n\t\t);\n\n\t\t// NOTE: dynamic access to protected properties. We need this to prevent unwanted properties in those classes to be exposed,\n\t\t// however we need these properties for internal work of the class\n\t\tif (entityRepositoryInstance instanceof AbstractRepository) {\n\t\t\tif (!(entityRepositoryInstance as any)['manager'])\n\t\t\t\t(entityRepositoryInstance as any)['manager'] = this;\n\t\t} else {\n\t\t\tif (!entityMetadata) throw new CustomRepositoryCannotInheritRepositoryError(customRepository);\n\t\t\t(entityRepositoryInstance as any)['manager'] = this;\n\t\t\t(entityRepositoryInstance as any)['metadata'] = entityMetadata;","sourceCodeStart":1279,"sourceCodeEnd":1315,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/typeorm/src/entity-manager/EntityManager.ts#L1279-L1315","documentation":"EntityManager.getCustomRepository looks up the supplied custom repository class in the global metadata args storage (populated by the @EntityRepository decorator). If no matching target is found, it throws CustomRepositoryNotFoundError. The check matches on the constructor function itself, so passing an undecorated class or the wrong class (e.g. an instance) fails.","triggerScenarios":"Calling `manager.getCustomRepository(UserRepo)` on a class that lacks the `@EntityRepository(Entity)` decorator; passing an instance instead of the class; importing the wrong class with the same name from a different module; decorator metadata not emitted because emitDecoratorMetadata/decorators are off in tsconfig.","commonSituations":"Custom repo class never decorated; decorator stripped by build config (Babel/swc with decorators disabled); circular imports causing the class identity passed to differ from the registered one; TS + esbuild target mismatch where decorators don't survive transpilation.","solutions":["Decorate the custom repository with `@EntityRepository(MyEntity)` (and import it at least once so the decorator runs).","Pass the class (constructor), not an instance: `getCustomRepository(UserRepo)` not `getCustomRepository(new UserRepo())`.","Ensure your tsconfig has `experimentalDecorators: true` and `emitDecoratorMetadata: true`, and that the build pipeline preserves decorators.","Break circular imports so the class registered equals the class referenced at the call site."],"exampleFix":"// before\nimport { Repository } from '@n8n/typeorm';\nclass UserRepo extends Repository<User> { /* no decorator */ }\nmanager.getCustomRepository(UserRepo); // -> not found\n\n// after\nimport { EntityRepository, Repository } from '@n8n/typeorm';\n@EntityRepository(User)\nclass UserRepo extends Repository<User> {\n  findActive() { return this.find({ where: { active: true } }); }\n}\nmanager.getCustomRepository(UserRepo);","handlingStrategy":"validation","validationCode":"import { getMetadataArgsStorage } from '@n8n/typeorm';\nfunction isRegisteredCustomRepo(repo: Function): boolean {\n  return getMetadataArgsStorage().entityRepositories.some(r => r.target === repo);\n}\nif (!isRegisteredCustomRepo(UserRepo)) {\n  throw new Error('UserRepo missing @EntityRepository decorator');\n}\nawait manager.getCustomRepository(UserRepo);","typeGuard":"function isCustomRepoClass<T>(v: unknown): v is new (...args: any[]) => T {\n  return typeof v === 'function';\n}","tryCatchPattern":null,"preventionTips":["Always decorate custom repos with @EntityRepository(Entity).","Set experimentalDecorators and emitDecoratorMetadata in tsconfig.","Pass the class, not an instance.","Avoid circular imports so the registered class identity matches the call site."],"tags":["typeorm","custom-repository","decorators","metadata"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}