问题描述
参考这里提出的问题
我认为它可能与nguniversal
有关,我创建了https://github.com/angular/universal/issues/2200 问题.我真的希望任何人都可以真正提供帮助.
当我运行 ng run serve-ssr
时,我希望 Angular 服务器会运行并观察更改,并且根据我的更改,它会重建(它做得非常好),但一切仍在继续直到发生错误或代码中出现错误.从这个意义上说,它会停止并退出.
我不知道这是否是一个错误,我只是将我的 angular 升级到 12 并将 nguniversal 升级到 v12,希望这个问题会消失,但它没有,我不知道去哪里.
我正在处理一个复杂的项目,从头开始编译需要一些时间.在开发环境中运行时,我出了事故并写错了东西,我会得到那个错误的错误,然后 this.debug is not a function
消息会出现,然后监视/编译器会停止.
angular.json
:
服务器":{builder":@angular-devkit/build-angular:server",选项":{输出路径":分布/服务器",主要":server.ts",tsConfig":tsconfig.server.json",sourceMap":真,优化":假},默认配置":"},为 ssr 构建":{builder":@angular-devkit/build-angular:browser",选项":{输出路径":分布/浏览器",索引":src/index.template.html",main":src/main.browser.ts",polyfills":src/polyfills.ts",tsConfig":src/tsconfig.app.json",aot":假,资产":[src/favicon.ico",src/manifest.json",源代码/资产",{glob":**/*",输入":node_modules/intro.js",输出":./assets/intro.js/"},{ "glob": "**/*", "input": "node_modules/monaco-editor", "output": "assets/monaco-editor";}],风格":[./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",src/styles.scss",node_modules/intro.js/introjs.css"],脚本":[node_modules/intro.js/intro.js"],vendorChunk":真的,extractLicenses":假,buildOptimizer":假,sourceMap":真,优化":假,namedChunks":真},默认配置":"},服务-ssr":{builder":@nguniversal/builders:ssr-dev-server",选项":{browserTarget":build-for-ssr",serverTarget":服务器"},},
我想出了这个问题,根据 这条评论,我更新了返回尝试>10 ||!allowedErrorCodes.includes(error.code)
到 return 尝试 >10000 ||!allowedErrorCodes.includes(error.code)
在这个文件 universal/modules/builders/src/ssr-dev-server/utils.ts
中,从那以后,我没有体验代码错误导致编译器退出或在开发过程中被中断.
唯一的技巧,如果您运行 ng run serve-ssr
时代码有问题,这不会产生影响.你仍然会得到 this.debug is not a function
仍然.但是一旦它被修复并且你运行它.无论您在代码中犯了什么错误,它都不会被中断.
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.
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"
},
},
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.
这篇关于如何防止 this.debug is not a function 导致编译器退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!