26

Ng serve and ng build --prod command working fine, but when I deploy the app on serve that time below error occurs:-

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,}
Kodiak
  • 5,978
  • 17
  • 35
Jay Senghani
  • 265
  • 1
  • 3
  • 9
  • I think you need to check the import statements for `Subject`. It must be imported like `import { Subject } from "rxjs/Subject"; `. Your project contains an import statement for `Subject` from somewhere else. – nevzatopcu Aug 05 '20 at 11:19
  • 1
    With the new angular10 version, the rxjs compat is removed and thus `Subject` should be imported from `import { Subject } from 'rxjs';` (not from `rxjs/Subject`) – Poul Kruijt Aug 05 '20 at 11:31
  • Great. I learned a new think about `Angular 10 & Rxjs 6`. Thanks for the correction. @PoulKruijt – nevzatopcu Aug 05 '20 at 11:34
  • I have used imports as mentioned. But I am still getting the same error. Any idea? – Revathi Sekar Sep 11 '20 at 12:49
  • you can reproduce same with using command `ng serve --prod` . No need to create build every time to check it. – Ambuj Khanna May 20 '21 at 07:06

3 Answers3

43

The problem will be solved in Angular 10 and later if you replace the import statement of subject as below.

Replace:

import { Subject } from "rxjs/Subject";

with:

import { Subject } from "rxjs";
StackOverflowUser
  • 945
  • 12
  • 10
Ahmed Derbala
  • 446
  • 5
  • 3
1

If you come here to fix problem with angular-2-dropdown-multiselect, just update to the latest version.(actually 1.9.0).

Rafael Lucini
  • 589
  • 3
  • 14
0

This error can occur due to outdated packages. If you have fixed the imports in all the project source files, then check inside the node_modules folder and find the packages which use rxjs/Subject. It will get fixed after updating those packages to their latest compatible versions.

In my case, it was due to the package aws-amplify-angular with Angular 10. Updating it and aws-amplify to the latest version solved the issue.

Tip: To find the libraries with old imports do a global search in the node_modules folder

Binara Medawatta
  • 512
  • 1
  • 9
  • 28