title: Angular Universal SSR: dev and build work, serve doesn't
body: <p>When I run <code>npm run dev:ssr</code> my Angular App <strong>works perfect including SSR</strong>.</p>
  <p>When I run <code>npm run build:ssr</code> it finishes without errors and creates my dist/PROJECT_NAME folder.</p>
  <p>Then when I try to run <code>npm run serve:ssr</code> the server starts to listen (also no errors).</p>
  <p><strong>The app works fine when I visit http://localhost:4000 but there is no SSR happening.
  I don't get any errors.</strong></p>
  <p><em>Anyone has any idea why that is or how I could debug this?</em></p>
  <p>I'm using Angular v9.</p>
  <p>** Update March 25:
  I upgraded angular to version 11. But still the same behavior. dev:ssr works. Production SSR doesn't.</p>
  <p>** Update March 26:
  I tested the sample application from <a href="https://angular.io/guide/universal" rel="nofollow noreferrer">https://angular.io/guide/universal</a>
  The sample application works exactly in the same way. Also no SSR happening while in production mode with <code>npm run serve:ssr</code></p>
  <p>** Update March 31:
  As requested, here are the contents of package.json</p>
  <pre><code>{
    &quot;name&quot;: &quot;angular.io-example&quot;,
    &quot;version&quot;: &quot;0.0.0&quot;,
    &quot;description&quot;: &quot;Example project from an angular.io guide.&quot;,
    &quot;license&quot;: &quot;MIT&quot;,
    &quot;scripts&quot;: {
      &quot;ng&quot;: &quot;ng&quot;,
      &quot;start&quot;: &quot;ng serve&quot;,
      &quot;build&quot;: &quot;ng build&quot;,
      &quot;test&quot;: &quot;ng test&quot;,
      &quot;lint&quot;: &quot;ng lint&quot;,
      &quot;e2e&quot;: &quot;ng e2e&quot;,
      &quot;dev:ssr&quot;: &quot;ng run angular.io-example:serve-ssr&quot;,
      &quot;serve:ssr&quot;: &quot;node dist/server/main.js&quot;,
      &quot;build:ssr&quot;: &quot;ng build --prod &amp;&amp; ng run angular.io-example:server:production&quot;,
      &quot;prerender&quot;: &quot;ng run angular.io-example:prerender&quot;
    },
    &quot;private&quot;: true,
    &quot;dependencies&quot;: {
      &quot;@angular/animations&quot;: &quot;~11.0.1&quot;,
      &quot;@angular/common&quot;: &quot;~11.0.1&quot;,
      &quot;@angular/compiler&quot;: &quot;~11.0.1&quot;,
      &quot;@angular/core&quot;: &quot;~11.0.1&quot;,
      &quot;@angular/forms&quot;: &quot;~11.0.1&quot;,
      &quot;@angular/platform-browser&quot;: &quot;~11.0.1&quot;,
      &quot;@angular/platform-browser-dynamic&quot;: &quot;~11.0.1&quot;,
      &quot;@angular/platform-server&quot;: &quot;~11.0.1&quot;,
      &quot;@angular/router&quot;: &quot;~11.0.1&quot;,
      &quot;@nguniversal/express-engine&quot;: &quot;^11.0.0&quot;,
      &quot;angular-in-memory-web-api&quot;: &quot;~0.11.0&quot;,
      &quot;express&quot;: &quot;^4.15.2&quot;,
      &quot;rxjs&quot;: &quot;~6.6.0&quot;,
      &quot;tslib&quot;: &quot;^2.0.0&quot;,
      &quot;zone.js&quot;: &quot;~0.10.3&quot;
    },
    &quot;devDependencies&quot;: {
      &quot;@angular-devkit/build-angular&quot;: &quot;~0.1100.2&quot;,
      &quot;@angular/cli&quot;: &quot;~11.0.2&quot;,
      &quot;@angular/compiler-cli&quot;: &quot;~11.0.1&quot;,
      &quot;@nguniversal/builders&quot;: &quot;^11.0.0&quot;,
      &quot;@types/express&quot;: &quot;^4.17.8&quot;,
      &quot;@types/jasmine&quot;: &quot;~3.6.0&quot;,
      &quot;@types/node&quot;: &quot;^12.11.1&quot;,
      &quot;codelyzer&quot;: &quot;^6.0.0&quot;,
      &quot;jasmine-core&quot;: &quot;~3.6.0&quot;,
      &quot;jasmine-marbles&quot;: &quot;~0.6.0&quot;,
      &quot;jasmine-spec-reporter&quot;: &quot;~5.0.0&quot;,
      &quot;karma&quot;: &quot;~5.1.0&quot;,
      &quot;karma-chrome-launcher&quot;: &quot;~3.1.0&quot;,
      &quot;karma-coverage&quot;: &quot;~2.0.3&quot;,
      &quot;karma-jasmine&quot;: &quot;~4.0.0&quot;,
      &quot;karma-jasmine-html-reporter&quot;: &quot;^1.5.0&quot;,
      &quot;protractor&quot;: &quot;~7.0.0&quot;,
      &quot;ts-node&quot;: &quot;~8.3.0&quot;,
      &quot;tslint&quot;: &quot;~6.1.0&quot;,
      &quot;typescript&quot;: &quot;~4.0.3&quot;
    }
  }
  </code></pre>
  <p>And angular.json</p>
  <pre><code>{
    &quot;$schema&quot;: &quot;./node_modules/@angular/cli/lib/config/schema.json&quot;,
    &quot;version&quot;: 1,
    &quot;newProjectRoot&quot;: &quot;projects&quot;,
    &quot;projects&quot;: {
      &quot;angular.io-example&quot;: {
        &quot;projectType&quot;: &quot;application&quot;,
        &quot;schematics&quot;: {
          &quot;@schematics/angular:application&quot;: {
            &quot;strict&quot;: true
          }
        },
        &quot;root&quot;: &quot;&quot;,
        &quot;sourceRoot&quot;: &quot;src&quot;,
        &quot;prefix&quot;: &quot;app&quot;,
        &quot;architect&quot;: {
          &quot;build&quot;: {
            &quot;builder&quot;: &quot;@angular-devkit/build-angular:browser&quot;,
            &quot;options&quot;: {
              &quot;outputPath&quot;: &quot;dist/browser&quot;,
              &quot;index&quot;: &quot;src/index.html&quot;,
              &quot;main&quot;: &quot;src/main.ts&quot;,
              &quot;polyfills&quot;: &quot;src/polyfills.ts&quot;,
              &quot;tsConfig&quot;: &quot;tsconfig.app.json&quot;,
              &quot;aot&quot;: true,
              &quot;assets&quot;: [
                &quot;src/favicon.ico&quot;,
                &quot;src/assets&quot;
              ],
              &quot;styles&quot;: [
                &quot;src/styles.css&quot;
              ],
              &quot;scripts&quot;: []
            },
            &quot;configurations&quot;: {
              &quot;production&quot;: {
                &quot;fileReplacements&quot;: [
                  {
                    &quot;replace&quot;: &quot;src/environments/environment.ts&quot;,
                    &quot;with&quot;: &quot;src/environments/environment.prod.ts&quot;
                  }
                ],
                &quot;optimization&quot;: true,
                &quot;outputHashing&quot;: &quot;all&quot;,
                &quot;sourceMap&quot;: false,
                &quot;namedChunks&quot;: false,
                &quot;extractLicenses&quot;: true,
                &quot;vendorChunk&quot;: false,
                &quot;buildOptimizer&quot;: true,
                &quot;budgets&quot;: [
                  {
                    &quot;type&quot;: &quot;initial&quot;,
                    &quot;maximumWarning&quot;: &quot;500kb&quot;,
                    &quot;maximumError&quot;: &quot;1mb&quot;
                  },
                  {
                    &quot;type&quot;: &quot;anyComponentStyle&quot;,
                    &quot;maximumWarning&quot;: &quot;2kb&quot;,
                    &quot;maximumError&quot;: &quot;4kb&quot;
                  }
                ]
              }
            }
          },
          &quot;serve&quot;: {
            &quot;builder&quot;: &quot;@angular-devkit/build-angular:dev-server&quot;,
            &quot;options&quot;: {
              &quot;browserTarget&quot;: &quot;angular.io-example:build&quot;
            },
            &quot;configurations&quot;: {
              &quot;production&quot;: {
                &quot;browserTarget&quot;: &quot;angular.io-example:build:production&quot;
              }
            }
          },
          &quot;extract-i18n&quot;: {
            &quot;builder&quot;: &quot;@angular-devkit/build-angular:extract-i18n&quot;,
            &quot;options&quot;: {
              &quot;browserTarget&quot;: &quot;angular.io-example:build&quot;
            }
          },
          &quot;test&quot;: {
            &quot;builder&quot;: &quot;@angular-devkit/build-angular:karma&quot;,
            &quot;options&quot;: {
              &quot;main&quot;: &quot;src/test.ts&quot;,
              &quot;polyfills&quot;: &quot;src/polyfills.ts&quot;,
              &quot;tsConfig&quot;: &quot;tsconfig.spec.json&quot;,
              &quot;karmaConfig&quot;: &quot;karma.conf.js&quot;,
              &quot;assets&quot;: [
                &quot;src/favicon.ico&quot;,
                &quot;src/assets&quot;
              ],
              &quot;styles&quot;: [
                &quot;src/styles.css&quot;
              ],
              &quot;scripts&quot;: []
            }
          },
          &quot;lint&quot;: {
            &quot;builder&quot;: &quot;@angular-devkit/build-angular:tslint&quot;,
            &quot;options&quot;: {
              &quot;tsConfig&quot;: [
                &quot;tsconfig.app.json&quot;,
                &quot;tsconfig.spec.json&quot;,
                &quot;e2e/tsconfig.json&quot;
              ],
              &quot;exclude&quot;: [
                &quot;**/node_modules/**&quot;
              ]
            }
          },
          &quot;e2e&quot;: {
            &quot;builder&quot;: &quot;@angular-devkit/build-angular:protractor&quot;,
            &quot;options&quot;: {
              &quot;protractorConfig&quot;: &quot;e2e/protractor.conf.js&quot;,
              &quot;devServerTarget&quot;: &quot;angular.io-example:serve&quot;
            },
            &quot;configurations&quot;: {
              &quot;production&quot;: {
                &quot;devServerTarget&quot;: &quot;angular.io-example:serve:production&quot;
              }
            }
          },
          &quot;server&quot;: {
            &quot;builder&quot;: &quot;@angular-devkit/build-angular:server&quot;,
            &quot;options&quot;: {
              &quot;outputPath&quot;: &quot;dist/server&quot;,
              &quot;main&quot;: &quot;server.ts&quot;,
              &quot;tsConfig&quot;: &quot;tsconfig.server.json&quot;
            },
            &quot;configurations&quot;: {
              &quot;production&quot;: {
                &quot;outputHashing&quot;: &quot;media&quot;,
                &quot;fileReplacements&quot;: [
                  {
                    &quot;replace&quot;: &quot;src/environments/environment.ts&quot;,
                    &quot;with&quot;: &quot;src/environments/environment.prod.ts&quot;
                  }
                ],
                &quot;sourceMap&quot;: false,
                &quot;optimization&quot;: true
              }
            }
          },
          &quot;serve-ssr&quot;: {
            &quot;builder&quot;: &quot;@nguniversal/builders:ssr-dev-server&quot;,
            &quot;options&quot;: {
              &quot;browserTarget&quot;: &quot;angular.io-example:build&quot;,
              &quot;serverTarget&quot;: &quot;angular.io-example:server&quot;
            },
            &quot;configurations&quot;: {
              &quot;production&quot;: {
                &quot;browserTarget&quot;: &quot;angular.io-example:build:production&quot;,
                &quot;serverTarget&quot;: &quot;angular.io-example:server:production&quot;
              }
            }
          },
          &quot;prerender&quot;: {
            &quot;builder&quot;: &quot;@nguniversal/builders:prerender&quot;,
            &quot;options&quot;: {
              &quot;browserTarget&quot;: &quot;angular.io-example:build:production&quot;,
              &quot;serverTarget&quot;: &quot;angular.io-example:server:production&quot;,
              &quot;routes&quot;: [
                &quot;/&quot;
              ]
            },
            &quot;configurations&quot;: {
              &quot;production&quot;: {}
            }
          }
        }
      }
    },
    &quot;defaultProject&quot;: &quot;angular.io-example&quot;
  }
  </code></pre>
  <p>Both from the sample app I used. Downloaded here: <a href="https://angular.io/guide/universal" rel="nofollow noreferrer">https://angular.io/guide/universal</a></p>