Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR Error: Uncaught (in promise): TypeError: i.BehaviorSubject is not a constructor in Angular 10 SSR

enter image description here

I'm getting this issue after build successfully and run on browser with angular universal

Here is my package json :

{
  "name": "ssr",
  "version": "1.0.0",
  "private": true,
  "dependencies": {
    "@angular/animations": "10.0.5",
    "@angular/cdk": "10.1.0",
    "@angular/common": "10.0.5",
    "@angular/compiler": "10.0.5",
    "@angular/core": "10.0.5",
    "@angular/fire": "^6.0.2",
    "@angular/forms": "10.0.5",
    "@angular/http": "^7.2.16",
    "@angular/localize": "^10.0.5",
    "@angular/material": "10.1.0",
    "@angular/material-moment-adapter": "10.1.0",
    "@angular/platform-browser": "10.0.5",
    "@angular/platform-browser-dynamic": "10.0.5",
    "@angular/platform-server": "^10.0.5",
    "@angular/router": "10.0.5",
    "@ng-bootstrap/ng-bootstrap": "^7.0.0",
    "@ng-toolkit/universal": "^8.1.0",
    "@nguniversal/express-engine": "^10.0.1",
    "@types/jquery": "^3.5.1",
    "@types/node": "^8.10.62",
    "angular-in-memory-web-api": "^0.11.0",
    "angular-ng-autocomplete": "^2.0.1",
    "classlist.js": "^1.1.20150312",
    "codelyzer": "^6.0.0",
    "core-js": "2.6.9",
    "crypto-js": "^3.3.0",
    "express": "^4.15.2",
    "firebase": "^7.17.1",
    "hammerjs": "^2.0.8",
    "jquery": "^3.5.1",
    "localstorage-polyfill": "^1.0.1",
    "moment": "2.24.0",
    "ng2-slim-loading-bar": "^4.0.0",
    "ng5-slider": "^1.1.14",
    "ngx-order-pipe": "^2.0.4",
    "ngx-pagination": "^3.2.1",
    "ngx-spinner": "^10.0.1",
    "rxjs": "^6.6.0",
    "rxjs-compat": "^6.6.0",
    "sweetalert2": "^8.19.0",
    "tslib": "^1.13.0",
    "web-animations-js": "^2.3.2",
    "whatwg-fetch": "^3.2.0",
    "zone.js": "0.10.3"
  },
like image 566
Rahul Nakum Avatar asked Jul 30 '20 10:07

Rahul Nakum


3 Answers

I just updated my project to Angular 10 and started facing this issue. What i did was , wherever I had BehaviorSubject imports , i changed them from import { BehaviorSubject } from "rxjs/Rx"; to import { BehaviorSubject } from "rxjs";

This makes production build work without any error.

like image 135
Akash Sherkar Avatar answered Oct 23 '22 20:10

Akash Sherkar


I got solution, use rxjs-tslint and migrate all rxjs syntax : https://www.npmjs.com/package/rxjs-tslint

like image 4
Rahul Nakum Avatar answered Oct 23 '22 22:10

Rahul Nakum


I am able to solve this by using the build command as ng build --configuration=prod --aot= false --build-optimizer=false. Application is up and running for us now. But it's a work around only. We are trying to check few more ways without setting optimiser to false.Will update you.

like image 2
Madhu Avatar answered Oct 23 '22 22:10

Madhu