从Angular 8更新到9会导致生产构建出现“ ReferenceError:SomeAbstractModelClass未定义”

时间:2020-02-11 17:19:34

标签: angular angular-library angular9

我已经更新了Angular 8 app to Angular 9。如果我使用ng serve启动应用程序,那么一切运行正常,但是如果我使用ng serve --prod启动应用程序,则在运行时会出现以下错误。

ReferenceError: SomeAbstractModelClass is not defined
    at http://localhost:4200/main.js:1:330907
    at Module.zUnb (http://localhost:4200/main.js:1:331001)
    at l (http://localhost:4200/runtime.js:1:552)
    at Object.0 (http://localhost:4200/main.js:1:96)
    at l (http://localhost:4200/runtime.js:1:552)
    at t (http://localhost:4200/runtime.js:1:421)
    at Array.r [as push] (http://localhost:4200/runtime.js:1:293)
    at http://localhost:4200/main.js:1:47

我不知道问题可能出在哪里,因为所有内容在编译时都带有一些警告。

WARNING in .../projects/apps/editor/src/test.ts is part of the TypeScript compilation but it's unused.
Add only entry points to the 'files' or 'include' properties in your tsconfig.

我还尝试禁用常春藤。

  "angularCompilerOptions": {
    "enableIvy": false
  }

然后我收到以下错误消息:

ReferenceError: SomeOtherModelClass is not defined
    at http://localhost:4200/main.js:1:364834
    at Module.zUnb (http://localhost:4200/main.js:1:364923)
    at l (http://localhost:4200/runtime.js:1:552)
    at Object.0 (http://localhost:4200/main.js:1:96)
    at l (http://localhost:4200/runtime.js:1:552)
    at t (http://localhost:4200/runtime.js:1:421)
    at Array.r [as push] (http://localhost:4200/runtime.js:1:293)
    at http://localhost:4200/main.js:1:47

SomeOtherModelClass是扩展另一个抽象类的类。

该问题的原因可能是什么?如果可以提供更多信息,请告诉我。

2 个答案:

答案 0 :(得分:0)

这似乎是bug

如果在"emitDecoratorMetadata"中将false设置为tsconfig.json,则该应用也将在生产模式下运行。

答案 1 :(得分:0)

正如前面提到的,根 "emitDecoratorMetadata": false 中的 tsconfig.json 修复了它。

我还需要将它设置为 true 以用于 Jest 的 src/tsconfig.test.json,否则我不断收到此 DI 错误:

Can't resolve all parameters for StoreService: (?, ?)