After implementing a generic class as shown below, an issue seems to have arisen:
import { Logger } from '@nestjs/common';
import { PaginationOptionsInterface, Pagination } from './paginate';
import { Repository } from 'typeorm';
export class EntityService<T> {
private repository: Repository<T>;
constructor(repository) {
this.repository = repository;
}
async getEntityWithPagination(
options: PaginationOptionsInterface,
): Promise<Pagination<T>> {
const [results, total] = await this.repository.findAndCount({
take: options.limit,
skip: (options.page - 1) * options.limit,
});
return new Pagination<T>({ results, total });
}
}
I am also utilizing this class with other entity services, like so:
@Injectable()
export class CarService extends EntityService<CarEntity> {
constructor(
@InjectRepository(CarEntity)
private carRepository: Repository<CarEntity>,
) {
super(carRepository);
}
The code functions correctly when running npm run start:dev
, but it throws the following error when attempting to run in production using npm run start:prod
:
internal/modules/cjs/loader.js:582
throw err;
^
Error: Cannot find module 'src/shared/entity.service'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
at Function.Module._load (internal/modules/cjs/loader.js:506:25)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (/home/tejas/Code/web/project/dist/car/car.service.js:27:26)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e595978a8f808691a5d5cbd5cbd5">[email protected]</a> start:prod: `node dist/main.js`
npm ERR! Exit status 1
Attempts to resolve the issue by deleting the dist folder and updating packages were unsuccessful. The package.json configuration is provided below. Help with debugging would be greatly appreciated.
dependencies": {
"@nestjs/common": "^5.5.0",
"@nestjs/core": "^5.5.0",
"@nestjs/jwt": "^0.2.1",
"@nestjs/passport": "^5.1.0",
"@nestjs/typeorm": "^5.2.2",
"bcryptjs": "^2.4.3",
"glob": "^7.1.3",
"passport": "^0.4.0",
"passport-http-bearer": "^1.0.1",
"passport-jwt": "^4.0.0",
"pg": "^7.7.1",
"reflect-metadata": "^0.1.12",
"rimraf": "^2.6.2",
"rxjs": "^6.2.2",
"typeorm": "^0.2.9",
"typescript": "^3.2.2"
},
"devDependencies": {
"@nestjs/testing": "^5.5.0",
"@types/express": "^4.16.0",
"@types/jest": "^23.3.1",
"@types/node": "^10.12.18",
"@types/supertest": "^2.0.7",
"jest": "^23.5.0",
"nodemon": "^1.18.9",
"prettier": "^1.14.2",
"supertest": "^3.1.0",
"ts-jest": "^23.1.3",
"ts-loader": "^4.4.2",
"ts-node": "^7.0.1",
"tsconfig-paths": "^3.5.0",
"tslint": "5.11.0",
"webpack": "^4.28.2",
"webpack-cli": "^3.1.2",
"webpack-node-externals": "^1.7.2"
},