How can we prevent this.debug is not a function from causing the compiler to exit

Viewed 645

In reference to the question asked here this.debug is not a function Angular Universal . it is correct that this.debug is not a function is just a side effect, however such error leads the compiler to stop (when watching) during the development.

How can I prevent such behavior on such errors?

Also, it sometimes just randomly simply stops, see screenshot below, it shows compilation complete then angular is listening then after I refreshed the UI, it just simply stopped no errors nothing.

enter image description here

I think it might be related to nguniversal, I created https://github.com/angular/universal/issues/2200 issue. I really hope anyone can really help.

When I run ng run serve-ssr, I expect the angular server will run and watch for changes, and per my changes, it would rebuild (which it does pretty great) but all that continues just till an error happens or a mistake in the code. In that sense, it would stop and exit.

I don't know if this is a bug or not, I just upgraded my angular to 12 and nguniversal to v12 hoping that this issue would go away but it didn't and I don't know where to go.

I am working on a complicated project that takes some good time to compile from scratch. When running in dev environment and I make a accident and write something wrong, I'd get the error of that wrong and then the this.debug is not a function message will come up then the watch/compiler will stop.

angular.json:

"server": {
          "builder": "@angular-devkit/build-angular:server",
          "options": {
            "outputPath": "dist/server",
            "main": "server.ts",
            "tsConfig": "tsconfig.server.json",
            "sourceMap": true,
            "optimization": false
          },
          "defaultConfiguration": ""
        },
"build-for-ssr": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/browser",
            "index": "src/index.template.html",
            "main": "src/main.browser.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "aot": false,
            "assets": [
              "src/favicon.ico",
              "src/manifest.json",
              "src/assets",
              {
                "glob": "**/*",
                "input": "node_modules/intro.js",
                "output": "./assets/intro.js/"
              },
              { "glob": "**/*", "input": "node_modules/monaco-editor", "output": "assets/monaco-editor" }
            ],
            "styles": [
              "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
              "src/styles.scss",
              "node_modules/intro.js/introjs.css"
            ],
            "scripts": ["node_modules/intro.js/intro.js"],
            "vendorChunk": true,
            "extractLicenses": false,
            "buildOptimizer": false,
            "sourceMap": true,
            "optimization": false,
            "namedChunks": true
          },
          "defaultConfiguration": ""
        },
"serve-ssr": {
          "builder": "@nguniversal/builders:ssr-dev-server",
          "options": {
            "browserTarget": "build-for-ssr",
            "serverTarget": "server"
          },
        },
1 Answers

I figured the issue, as per this comment, I updated return attempts > 10 || !allowedErrorCodes.includes(error.code) to return attempts > 10000 || !allowedErrorCodes.includes(error.code) in this file universal/modules/builders/src/ssr-dev-server/utils.ts, and ever since, I didn't experience the compiler exiting or gets interrupted during development when a mistake in the code is done.

The only trick, this won't impact if you run ng run serve-ssr with something wrong in the code. You'd still get this.debug is not a function still. But once it's fixed and you run it. it won't get interrupted regardless the mistake you do in the code.

Related