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

时间:2018-10-16 07:13:08

标签: javascript angular mean-stack

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

>>> from collections_extended import setlist
>>> sl = setlist('abracadabra')
>>> sl
setlist(('a', 'b', 'r', 'c', 'd'))
>>> sl[3]
'c'
>>> sl[-1]
'd'
>>> 'r' in sl  # testing for inclusion is fast
True
>>> sl.index('d')  # so is finding the index of an element
4
>>> sl.insert(1, 'd')  # inserting an element already in raises a ValueError
ValueError
>>> sl.index('d')
4

我不知道为什么会这样,因为当我运行它时,使用ng-build --prod而不使用> 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) ,我的应用程序运行良好。这是我的 main.ts 文件:

ng-build

在我的 app.module.ts 下面:

--prod

更新: 当我使用 ng serve --prod 编译项目时,没有发现vendor.js:

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));
});

但是当我编译 ng服务 vendor.js时发现:

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() {

  }
}

1 个答案:

答案 0 :(得分:0)

如果问题仅在于产品构建,并且您的应用程序在ng serve上运行良好,请尝试执行此操作:

npm缓存清理--force

npm安装

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