currently I am working on a project where I want to build a NodeJS application which runs on CloudFoundry. The application should provide some data from a database. To realize the requirements I use NestJs and TypeORM.
When I run the application on my local computer everything works fine. But when I try to push the app to Cloud Foundry (using cf push) this error occurs:
2019-10-13T20:21:47.85+0200 [APP/PROC/WEB/0] ERR internal/modules/cjs/loader.js:638
2019-10-13T20:21:47.85+0200 [APP/PROC/WEB/0] ERR throw err;
2019-10-13T20:21:47.85+0200 [APP/PROC/WEB/0] ERR ^
2019-10-13T20:21:47.85+0200 [APP/PROC/WEB/0] ERR Error: Cannot find module 'src/allocation/allocation.entity'
2019-10-13T20:21:47.85+0200 [APP/PROC/WEB/0] ERR at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
2019-10-13T20:21:47.85+0200 [APP/PROC/WEB/0] ERR at Function.Module._load (internal/modules/cjs/loader.js:562:25)
2019-10-13T20:21:47.85+0200 [APP/PROC/WEB/0] ERR at Module.require (internal/modules/cjs/loader.js:690:17)
2019-10-13T20:21:47.85+0200 [APP/PROC/WEB/0] ERR at require (internal/modules/cjs/helpers.js:25:18)
2019-10-13T20:21:47.85+0200 [APP/PROC/WEB/0] ERR at Object.<anonymous> (/home/vcap/app/dist/user/user.entity.js:12:29)
2019-10-13T20:21:47.85+0200 [APP/PROC/WEB/0] ERR at Module._compile (internal/modules/cjs/loader.js:776:30)
2019-10-13T20:21:47.85+0200 [APP/PROC/WEB/0] ERR at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
2019-10-13T20:21:47.85+0200 [APP/PROC/WEB/0] ERR at Module.load (internal/modules/cjs/loader.js:653:32)
2019-10-13T20:21:47.85+0200 [APP/PROC/WEB/0] ERR at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
2019-10-13T20:21:47.85+0200 [APP/PROC/WEB/0] ERR at Function.Module._load (internal/modules/cjs/loader.js:585:3)
I figured out that the error only occurs if I use TypeORMs Join Decorators (e.g. @OneToMany or @ManyToOne).
This is the source code of "allocation.entity" and "user.entity" (I ommited some properties of the class, to show only the relevant content):
(allocation.entity.ts):
import { Entity, Column, PrimaryColumn, ManyToOne } from 'typeorm';
import { UserEntity } from 'src/user/user.entity';
@Entity()
export class AllocationEntity {
@ManyToOne(() => UserEntity, user => user.allocations)
user: UserEntity;
}
(user.entity.ts):
import { AllocationEntity } from 'src/allocation/allocation.entity';
import { Entity, Column, PrimaryColumn, OneToMany } from 'typeorm';
@Entity()
export class UserEntity {
@OneToMany(() => AllocationEntity, allocation => allocation.user)
allocations: AllocationEntity[];
}
Has anyone an idea how to solve that problem?
Thx in advance!
f1a2buge