o.Subject不是构造函数-Angular 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,}

如果将的import语句替换为主题如下。

替换:

import { Subject } from "rxjs/Subject";

带有:

import { Subject } from "rxjs";

如果您来这里是为了解决angular-2-下拉多选的问题,只需更新到最新版本即可。(实际为1.9.0(.

此错误可能是由于软件包过期造成的。如果已经修复了所有项目源文件中的导入,请在node_modules文件夹中进行检查,并找到使用rxjs/Subject的包。在将这些软件包更新到最新的兼容版本后,它将得到修复。

在我的情况下,这是由于包aws-amplify-angular与Angular 10。将它和aws-amplify更新到最新版本解决了这个问题。

提示:要查找具有旧导入的库,请在node_modules文件夹中进行全局搜索

最新更新