I have been utilizing TypeORM smoothly for some time, but out of the blue, I encountered this error during an API call:
EntityMetadataNotFound: No metadata for "BusinessApplication" was found.
at new EntityMetadataNotFoundError (C:\Users\Robbie\Code\fit-society\node_modules\typeorm\error\EntityMetadataNotFoundError.js:10:28)
at Connection.getMetadata (C:\Users\Robbie\Code\fit-society\node_modules\typeorm\connection\Connection.js:336:19)
at EntityManager.<anonymous> (C:\Users\Robbie\Code\fit-society\node_modules\typeorm\entity-manager\EntityManager.js:459:44)
...
<p>The issue arises when this piece of code is executed:</p>
<pre class="lang-js"><code>import { BusinessApplication } from '../../../backend/all-entities';
import db from '../../../backend/database';
// within a function...
const manager = await db.getManager();
// in this case, req.data.id does equal "oldest"
const application: BusinessApplication | undefined =
req.data.id === 'oldest'
? (await manager.find(BusinessApplication, { order: { dateSubmitted: 'DESC' }, take: 1 }))[0]
: await manager.findOne(BusinessApplication, { where: { id: parseInt(req.data.id, 10) } });
if (application == null) throw createError(404, 'Business application not found');
return application;
In backend/all-entities.ts:
...In backend/database.ts:
...In backend/entities/BusinessApplication.ts:
...Despite having everything seemingly set up correctly with imports and decorators in place, why am I still facing this error? Interestingly, changing
await manager.find(BusinessApplication, ...)
to await manager.find('BusinessApplication', ...)
resolves the issue, but it sacrifices intellisense. Also, this error only occurs after a hot-module-reload by Webpack, typically triggered by changes in the codebase or page disposal in Next.js.