角度未捕获错误:未找到"kc"的 NgModule 元数据



我在运行我的 MEAN Stack 应用程序时遇到问题ng-build --prod使用命令。我的终端运行良好,没有发生错误。但是当我在 localhost:4200 中打开浏览器时,我的应用程序没有显示任何内容。然后控制台给我这个错误:

> Uncaught Error: No NgModule metadata found for 'kc'.
at e.resolve (main.371a82c9fcb51afc1df0.js:1)
at e.getNgModuleMetadata (main.371a82c9fcb51afc1df0.js:1)
at e._loadModules (main.371a82c9fcb51afc1df0.js:1)
at e._compileModuleAndComponents (main.371a82c9fcb51afc1df0.js:1)
at e.compileModuleAsync (main.371a82c9fcb51afc1df0.js:1)
at e.compileModuleAsync (main.371a82c9fcb51afc1df0.js:1)
at e.bootstrapModule (main.371a82c9fcb51afc1df0.js:1)
at Object.zUnb (main.371a82c9fcb51afc1df0.js:1)
at p (runtime.a66f828dca56eeb90e02.js:1)
at Object.3 (main.371a82c9fcb51afc1df0.js:1)

我不知道为什么会发生这种情况,因为当我运行时,使用ng-build而不--prod,我的应用程序运行良好。这是我的主要.ts文件:

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
import 'hammerjs';
if (environment.production) {
enableProdMode();
}
const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule);
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.log(err));

document.addEventListener('DOMContentLoaded', () => {
platformBrowserDynamic().bootstrapModule(AppModule).then(() => {
if ('serviceWorker' in navigator && environment.production) {
navigator.serviceWorker.register('/ngsw-worker.js');
}
})
.catch(err => console.log(err));
});

在我的应用程序模块下面

import { Component } from '@angular/core';
import { AuthService } from '../services/auth.service';
import { Router } from '@angular/router';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})

export class AppComponent {
title = 'Internship Program Tracer';
constructor(
private authService : AuthService,
private router : Router,
){
}
ngOnInit() {
}
}

更新: 当我使用ng serve --prod编译我的项目时,没有供应商.js找到:

Date: 2018-10-16T22:20:26.127Z
Hash: d2be935ebafc240e254f
Time: 57889ms
chunk {0} runtime.a66f828dca56eeb90e02.js (runtime) 1.05 kB [entry] [rendered]
chunk {1} styles.ad29f085d4a251cb6386.css (styles) 43.9 kB [initial] [rendered]
chunk {2} polyfills.19a6a3da76674acaee2e.js (polyfills) 59.1 kB [initial] [rendered]
chunk {3} main.9f6403673fe64ddd0b86.js (main) 684 kB [initial] [rendered]
i 「wdm」: Compiled successfully.

但是当我编译ng服务供应商时.js发现:

Date: 2018-10-16T22:23:38.817Z
Hash: 91cb9d988bc421669cc9
Time: 23624ms
chunk {main} main.js, main.js.map (main) 289 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 224 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 5.22 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 62.1 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 6.5 MB [initial] [rendered]
i 「wdm」: Compiled successfully.

如果问题仅与 prod build 有关,并且您的应用程序在 ng serve 上运行良好,请尝试这样做:

npm 缓存清理 --强制

npm 安装

npm install --save-dev @angular/cli@latest

相关内容

最新更新