core.js:4197错误TypeError:无法将类作为函数调用

时间:2020-08-12 05:48:00

标签: javascript angular typescript angular-cli-v9

在服务Angular应用程序时,出现Angular v10中的控制台错误以下情况

core.js:4197 ERROR TypeError: Cannot call a class as a function
    at _classCallCheck (classCallCheck.js:3)
    at new Button (button.js:36)
    at ButtonComponent.<anonymous> (createSuper.js:12)
    at new ButtonComponent (button.component.ts:30)
    at NodeInjectorFactory.ButtonComponent_Factory [as factory] (button.component.ts:57)
    at getNodeInjectable (core.js:4029)
    at instantiateAllDirectives (core.js:8092)
    at createDirectivesInstances (core.js:7474)
    at ɵɵelementStart (core.js:14001)
    at SBController_Template (template.html:114)

演示:https://github.com/kumaresan-subramani/AngularSampleIssue

复制步骤:

  1. npm我
  2. npm运行开始

有角团队的答案-https://github.com/angular/angular-cli/issues/18125#issuecomment-672069800

1 个答案:

答案 0 :(得分:1)

我确实看过你的回购。看来您的target文件中的ES es5已设置为tsconfig.base.json,但不支持类。我认为您必须至少从es6es2015)进行设置,然后才能正常工作:

{
  "compilerOptions": {
    "target": "es2015",
  }
}