shy2net / nestjs-angular-starter

A starter template\boilerplate to work with NodeJS (typescript), Angular (with SSR), and shared models.
https://nemex-studios.com
MIT License
31 stars 17 forks source link

NX implementation #5

Closed benjaminforras closed 2 years ago

benjaminforras commented 2 years ago

Hi! I'm trying to implement this integration with the SSR and NestJS in a NX monorepo. Building the app is fine. However, when I try run it, I encounter the following error message when I mount the Angular SSR server:

Error: Cannot find module 'C:\Users\user\Documents\Projects\nx-nestjs-angular-ssr-starter\dist\apps\frontend\server\main'
    at webpackEmptyContext (C:\Users\user\Documents\Projects\nx-nestjs-angular-ssr-starter\dist\apps\backend\main.js:1:85)
    at exports.mountAngularSSR (C:\Users\user\Documents\Projects\nx-nestjs-angular-ssr-starter\dist\apps\backend\main.js:1:2490)
    at C:\Users\user\Documents\Projects\nx-nestjs-angular-ssr-starter\dist\apps\backend\main.js:1:4206
    at Generator.next (<anonymous>)
    at fulfilled (C:\Users\user\Documents\Projects\nx-nestjs-angular-ssr-starter\node_modules\tslib\tslib.js:115:62) {
  code: 'MODULE_NOT_FOUND'
}

I did not change much, just changed some of the outputPath's to match NX's. Every file is in place Can you help me with this?

shy2net commented 2 years ago

Hey there, sorry for the late response. How are you building NestJS and angular? are you using the built-in build.sh script? are you using the docker build? are you building it manually?

benjaminforras commented 2 years ago

No problem, I'm using NX's build command, like this: nx build

shy2net commented 2 years ago

In order to use SSR, you will also need to build the angular part and move the angular dist into the appropriate directory in your dist. Have a look at the build.sh to see how it builds Angular and where it copies the dist files, this is important because express will then mount it from that target directory. Also make sure to add to your production.json (if it's running on production) the following:

  "ANGULAR": {
    "MOUNT": "true",
   "USE_SSR": "true"
  }
benjaminforras commented 2 years ago

Okay, I got this, but when I require the file itself inside the angular-mounter.ts file it'll throw the error in the issue description

shy2net commented 2 years ago

Hey, can you please write the error?