【问题标题】:o.Subject is not a constructor - Angular 10o.Subject 不是构造函数 - Angular 10
【发布时间】:2020-11-25 12:50:10
【问题描述】:

Ng serveng build --prod 命令工作正常,但是当我在 serve 上部署应用程序时,会出现以下错误:-

TypeError: o.Subject is not a constructor
at new e (vendor-esnext.js:1)
at Object.useFactory (vendor-esnext.js:1)
at Object.i [as factory] (vendor-esnext.js:1)
at Xo.hydrate (vendor-esnext.js:1)
at Xo.get (vendor-esnext.js:1)
at Jf.get (vendor-esnext.js:1)
at Object.get (vendor-esnext.js:1)
at Gn (vendor-esnext.js:1)
at Module.Sl (vendor-esnext.js:1)
at Mn.e.ɵfac [as factory] (vendor-esnext.js:1)

tsconfig.base.json

{"compilerOptions": {
"baseUrl": "",
"allowSyntheticDefaultImports": true,
"declaration": false,
"downlevelIteration": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
  "dom",
  "es2017"
],
"module": "esnext",
"moduleResolution": "node",
"sourceMap": true,
"target": "ESNext",
"paths": {
  "@angular/*": [
    "node_modules/@angular/*"
  ]
}},"include": [
"src/**/*.ts",
"node_modules/ng4-fittext/*.d.ts"],"exclude": [],"compileOnSave": false,}

【问题讨论】:

  • 我认为您需要检查 Subject 的导入语句。它必须像import { Subject } from "rxjs/Subject"; 一样导入。您的项目包含来自其他地方的 Subject 的导入语句。
  • 使用新的 angular10 版本,删除了 rxjs 兼容,因此应该从 import { Subject } from 'rxjs'; 导入 Subject(而不是从 rxjs/Subject
  • 太棒了。我对Angular 10 & Rxjs 6 有了新的认识。感谢您的指正。 @PoulKruijt
  • 我已经使用了前面提到的导入。但我仍然遇到同样的错误。有什么想法吗?
  • 您可以使用命令 ng serve --prod 重现相同的内容。无需每次都创建构建来检查它。

标签: angular rxjs angular10


【解决方案1】:

如果您替换 import 语句,该问题将在 Angular 10 及更高版本中得到解决 题目如下。

替换:

import { Subject } from "rxjs/Subject";

与:

import { Subject } from "rxjs";

【讨论】:

  • 从 'rxjs/Observable' 导入 { Observable } 也是如此。这也应该替换为 import { Observable } from 'rxjs'
  • 对我不起作用!我用import { Subject, Observable } from 'rxjs';
【解决方案2】:

如果您来这里解决 angular-2-dropdown-multiselect 的问题,只需更新到最新版本。(实际上是 1.9.0)。

【讨论】:

    猜你喜欢
    • 2020-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-13
    • 2016-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多