【发布时间】:2021-06-07 15:31:43
【问题描述】:
突然间,当我构建并部署到 IIS 服务器时,我的 Angular 代码出现了 Invalid ng target 错误和空白页。我无法弄清楚发生了什么变化。我有多个 envt 文件,在这种情况下,我正在使用我的开发环境文件进行构建。这一直工作到五月中旬,突然间它停止了工作。我需要帮助来尝试找出问题以及如何解决它。
Error:main.b4e380d80b32ac5b2622.js:formatted:57352 Error: Invalid ng target
at Ka (main.b4e380d80b32ac5b2622.js:formatted:6629)
at Qa (main.b4e380d80b32ac5b2622.js:formatted:6635)
at main.b4e380d80b32ac5b2622.js:formatted:10927
at t.get [as listeners] (main.b4e380d80b32ac5b2622.js:formatted:10950)
at e.listen (main.b4e380d80b32ac5b2622.js:formatted:12918)
at $p (main.b4e380d80b32ac5b2622.js:formatted:11482)
at wh (main.b4e380d80b32ac5b2622.js:formatted:11936)
at yh (main.b4e380d80b32ac5b2622.js:formatted:11890)
at hf (main.b4e380d80b32ac5b2622.js:formatted:12756)
at Object.Nh [as createRootView] (main.b4e380d80b32ac5b2622.js:formatted:12392)
这是 angular.json 中的构建开发配置 `
"configurations": {
"dev": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.dev.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
]
},`
这是项目的配置部分
"configurations": {
"production": {
"browserTarget": "myproject:build:production"
},
"dev": {
"browserTarget": "myproject:build:dev"
},
这里是 tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "ES5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
]
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
}
}
高级错误似乎来自 main.ts 在 platformBrowserDynamic().bootstrapModule(AppModule) .catch(err => console.error(err));
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
if (window) {
window.console.debug=function(){};
}
}
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.error(err));
【问题讨论】:
-
您使用的是哪个版本的 Angular?你能发布使用它的代码吗?
-
Angular CLI:8.3.26 Angular:8.2.14
-
您最近升级到 8 了吗?还是一直是 8?
-
使用 ng 构建?还是 ng build --watch?
-
尝试删除“node_models”并运行“npm install”