I am getting the following error when attempting to setup a set of TypeORM entities
file:///C:/Users/.../Projects/my-api/bin/models/entities/entity1.js:29 __metadata("design:type", Entity2) ^
ReferenceError: Cannot access 'Entity2' before initialization at file:///C:/Users/.../Projects/my-api/bin/models/entities/entity1.js:29:31 at ModuleJob.run (internal/modules/esm/module_job.js:152:23) at async Loader.import (internal/modules/esm/loader.js:166:24) at async Object.loadESM (internal/process/esm_loader.js:68:5)
This is occurring with the following setup
Nodejs - 14.16.0 TypeORM - 0.2.31 Typescript - 4.2.3 "mssql": "^6.3.1", "reflect-metadata": "^0.1.13",
This line is related to a ManyToOne decorator on entity1:
@ManyToOne(() => Entity2, (entity2) => entity2.column)
The code transpiles but when running the node command against the resulting js file, I get the error identified.
I tried what was proposed here: TypeORM OneToMany causes "ReferenceError: Cannot access '<Entity>' before initialization" but same error.
I have also confirmed all of the entities are registered with the connection.
Edit: This has to do with the way NodeJS is loading the entities. I tried reorganizing the entity order but it still fails. Is there a way to tell NodeJS to load entities in a specific order?