0

I am using the microservice hybrid example from nestjs (https://github.com/nestjs/nest/tree/master/sample/03-microservices) to get familiar with the basics. It currently uses a microservice that is located inside the src folder (src/math). I want to move the microservice in the root folder under a microservices folder (microservices/math/...) so that can build additional ones in this structure.

When i run it with "start:prod": "node dist/main.js" if the math.module I am importing in the app.module.ts is the one as per example, in './math/math.module' it works fine. If I copy the math folder content in the microservices folder in the root and i reference the math.module from '../microservices/math.module' then the dist structure is wrong where I have:

  • dist
    • microservices
    • src
      • common
      • math
      • app.module.d.ts
      • main.d.ts

Of course, in this case, it will try to run main.js inside "dist" but it's no longer there it's it is automatically put inside the src rather than being in the root of the dist folder.

Is this purely a typescript configuration that i need to tweak?

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "noImplicitAny": false,
    "removeComments": true,
    "noLib": false,
    "allowSyntheticDefaultImports": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es6",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./"
  },
  "exclude": ["node_modules"]
}

tsconfig.build.json

{
  "extends": "./tsconfig.json",
  "include": ["src/**/*"],
  "exclude": ["node_modules", "**/*.spec.ts"]
}
M_M
  • 71
  • 2
  • 5
  • Are you compiling your project with the tsc command? This might be a configuration issue in your tsconfig.json file...paste it up. – Kevin Mansel Oct 09 '19 at 00:14
  • @KevinMansel I edited the answer with the tsconfigs. Also this example is to exemplify the issue i have in another project, which is more elaborate to share (nestjs with ssr, hybrid microservice setup, angular, etc). – M_M Oct 09 '19 at 07:26
  • @KevinMansel do you have any idea? – M_M Oct 11 '19 at 17:12

1 Answers1

2

The problem here is that, when you importing local code from folder, that is not included in tsconfig.json that is used for build. In that case typescript is going on parent folder of the most not deep folder with code, and builds structure of that folders tree, because built files should have the same relative paths to each other.

iamolegga
  • 915
  • 8
  • 8
  • so the setup i have here cannot work basically? It's not a big deal, I can change the structure, just to know so i don't waste time on it. – M_M Oct 24 '19 at 07:46
  • @M_M actually, it should work, it only change folders structure under `/dist` folder, and you should just change path to your built target file at your run script – iamolegga Oct 26 '19 at 15:21