[英]Angular Uncaught Error: No NgModule metadata found for 'kc'
I have problem while running my MEAN Stack app use ng-build --prod
command. 我在运行MEAN Stack应用程序时
ng-build --prod
问题,请使用ng-build --prod
命令。 My terminal running well, no error occurs. 我的终端运行良好,未发生任何错误。 But when I open the browser in localhost:4200, my app didn't show anything.
但是,当我在localhost:4200中打开浏览器时,我的应用程序未显示任何内容。 And then the console give me this error :
然后控制台给我这个错误:
> 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)
I don't know why this happen, because when I run it use ng-build
without --prod
, my app running well. 我不知道为什么会这样,因为当我运行它时,使用不带
--prod
ng-build
,我的应用程序运行良好。 This is my main.ts file : 这是我的main.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));
});
And below my app.module.ts : 在我的app.module.ts下面:
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() {
}
}
UPDATE : When I compiles my project using ng serve --prod there's no vendor.js found : 更新:当我使用ng serve --prod编译我的项目时,没有发现vendor.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.
But when I compiles ng serve vendor.js found : 但是当我编译ng服务 vendor.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.
Try doing this if the problem is only with prod build and your application works well on ng serve: 如果问题仅在于产品构建,并且您的应用程序在ng serve上运行良好,请尝试执行此操作:
npm cache clean --force npm缓存清理--force
npm install npm安装
npm install --save-dev @angular/cli@latest npm install --save-dev @ angular / cli @ latest
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.