简体   繁体   English

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

[英]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.

相关问题 错误:在Angular2中找不到“未定义”的NgModule元数据 - Error: No NgModule metadata found for 'undefined' in Angular2 未被捕获(承诺):错误:找不到“ [对象对象]”的NgModule元数据 - Uncaught (in promise): Error: No NgModule metadata found for '[object Object]' 构建 Angular 应用程序时,获取“未找到“类{}”错误的“未找到 NgModule 元数据” - Getting `No NgModule metadata found for 'class{}'` error when building angular application 错误:错误:找不到'AppComponent'的NgModule元数据 - Error: Error: No NgModule metadata found for 'AppComponent' 编译器失败 - 找不到“AppModule”的 NgModule 元数据中的错误 - Compiler fails - ERROR in No NgModule metadata found for 'AppModule' AngularUniversal 预渲染错误:UnhandledPromiseRejectionWarning:错误:找不到“类{}”的 NgModule 元数据 - AngularUniversal prerendering error: UnhandledPromiseRejectionWarning: Error: No NgModule metadata found for 'class{}' 找不到“ AppModule”的NgModule元数据中的错误。 和webpack:编译失败 - ERROR in No NgModule metadata found for 'AppModule'. and webpack: Failed to compile 未捕获(承诺):错误:未找到 MyOpportunitiesFilterPage 的组件工厂。 你把它添加到@NgModule.entryComponents 了吗? - Uncaught (in promise): Error: No component factory found for MyOpportunitiesFilterPage. Did you add it to @NgModule.entryComponents? Angular2PiwikModule 中的错误不是 NgModule - ERROR in Angular2PiwikModule is not an NgModule 重新安装node_modules后找不到“ AppModule”的NgModule元数据 - No NgModule metadata found for 'AppModule' after reinstalling node_modules
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM