出现此问题是因为在 Angular 中未定义 NODE_DEBUG 属性,导致读取时出现 undefined。解决方法是在代码中定义 NODE_DEBUG 属性,并给予相应的值,如下所示:
process.env.NODE_DEBUG = 'debug'; // 定义 NODE_DEBUG 属性并赋值为 'debug'
或者使用 angular.json 文件添加 NODE_DEBUG 属性,如下所示:
"architect": { "build": { "configurations": { "production": { "fileReplacements": [ { "replace": "src/app/environment.ts", "with": "src/app/environment.prod.ts" } ], "serviceWorker": true, "ngswConfigPath": "ngsw-config.json", "nodeOptions": { "NODE_DEBUG": "debug" // 添加 NODE_DEBUG 属性并赋值为 'debug' } } } } }
这样就可以解决此问题。