I have an issue while implementing my microservice network. The situation is next: I just finished the first microservice (let it be micro-A) and now I start working on another one (micro-B). I realize that I need to share DTO and some interfaces from micro-A to use them in micro-B. Because I need type-safe communication between them. I've investigated half of the internet and I didn't find an answer to this situation.
There are two ways of how people do this - using monorepo and npm packages. I'd like to use npm packages. So at this point, I decided to create a separate folder (let's name it api-interfaces) in my microservice where I will create index.ts file with such code:
export * from './src/users/dto/profile.res.dto';
export * from './src/users/dto/user.res.dto';
And then create a webpack config, which will copy all dependencies for api-interfaces/index.ts to api-interfaces/lib/*, and then publish it to npm.
Looks Ok, but then I got next errors:
Module not found: Error: Can't resolve '@nestjs/swagger' in '/micro-user/src/profiles/dto'
@ ../profiles/dto/profile.res.dto.ts 14:18-44
@ ../users/dto/user.res.dto.ts
@ ./index.ts
ERROR in ../profiles/dto/profile.res.dto.ts
Module not found: Error: Can't resolve 'class-transformer' in '/micro-user/src/profiles/dto'
@ ../profiles/dto/profile.res.dto.ts 13:28-56
@ ../users/dto/user.res.dto.ts
@ ./index.ts
Also, I use serialization via class-transformer. So at this moment, I stuck ... I've two questions: - do you have any idea how to share API DTOs and Interfaces between microservices? - can you help me with my webpack build?