TS2339 error occurs when the property 'takeUntil' is not found on the type 'Observable<Foo>' along with various other rxjs version 6 errors

After recently updating numerous packages in my Angular project, I encountered several compilation errors.

Previous package.json:

{
  "name": "data-jitsu",
  "version": "0.0.0",
  ... (old dependencies listed here)
}

New package.json:

{
  "name": "data-jitsu",
  "version": "0.0.0",
  ... (new dependencies listed here)
}

Upon running npm install using the updated package.json file followed by ng serve, multiple TS compilation errors were thrown:

ERROR in src/app/all-matches/all-matches.component.ts(35,39): error TS2339: Property 'takeUntil' does not exist on type 'Observable'. ... (more errors listed)

Much of these errors appeared to be related to rxjs, given that I upgraded from v5 to v6 which caused compatibility issues.

In an attempt to resolve the errors, I installed rxjs-compat with

npm install rxjs@6 rxjs-compat@6 --save
. However, this solution did not eliminate any of the existing errors.

Following recommendations, I ran ts-lint using the commands below for automation:

npm i -g rxjs-tslint
rxjs-5-to-6-migrate -p [path/to/tsconfig.json]

The output indicated no valid rules specified for JavaScript files, suggesting potential misuse of TypeScript conventions when working with rxjs.

Starting troubleshooting from the first error about 'takeUntil' method not existing on 'Observable', it became clear that module import errors like 'cannot find module foo' were prevalent throughout .ts files.

For instance, some import errors included: "@angular/core", "firebase/app", and "@angular/router". These problems are noticeable within app.module.ts as well.

If anyone has insights or solutions to address these importing issues, your assistance would be greatly appreciated!

Answer №1

You might still be using operators in the old rxjs 5.x style.

Here is a summary of the changes in rxjs6:

  1. The imports have changed. You now need to import Observable, Subject, BehaviorSubject, etc., and methods that used to be in 'rxjs/add/observable' differently. Now everything must be imported from 'rxjs'. For example:

    import {Observable, Subject, of, from} from 'rxjs'
    ;

    Additionally, all operators like map, concat, do (now called tap), etc., should be imported from rxjs/operators. So something like:

    import { map, tap, takeUntil} from 'rxjs/operators';

    Your imports seem correct.

  2. You should use pipes instead of chaining your operators. For example, in your all-matches.components.ts file, line 33, if you replace:

    this.authService.getCurrentUser().takeUntil(this.ngUnsubscribe).subscribe(user=>{

    with

    this.authService.getCurrentUser().pipe(takeUntil(this.ngUnsubscribe)).subscribe(user=>{

    the takeUntil error will disappear.

    Similarly, instead of Observable.of(true), you should import the of operator and use of(true).

    You can try this in your authorization.service.ts file. It will resolve all the "of errors."

    You may want to investigate this further.

  3. If you are encountering import errors with custom files, double-check whether the files actually exist. For instance:

    ERROR in src/app/app.module.ts(6,38): error TS2307: Cannot find module './api-keys'

    related to

    import { masterFirebaseConfig } from './api-keys'

    this error is normal if the file './api-keys' does not exist. PS: if keys are not stored in git, you may not encounter these errors.

  4. Regarding AngularFire5.0, make sure to use one of the operators :

    Db.list('items').subscribe(console.log)

    should be updated to (using the valueChanges method) :

    Db.list<Item>('items').valueChanges().subscribe(console.log)

    For more information, visit: https://github.com/angular/angularfire2/blob/master/docs/version-5-upgrade.md

Best of luck!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for implementing a search filter in a select dropdown menu using Angular

I am attempting to enhance my select option list by including a search filter. With numerous options available, I believe that having a search function will make it easier for the user to locate their desired selection. I hope my message is clear despite ...

Angular 2 encountered a fatal error: Issues with parsing the template:

Here is the code snippet I am currently working with: <div class="container"> <div [hidden]="loggedIn"> <md-grid-list cols="6" [style.margin-top]="'20px'"> <md-grid-tile [colspan]="1"></md-grid-tile> I have already ...

Implement Angular in a non-conventional Angular-based venture

Is there a way to incorporate Angular into a project that is built on a different framework? Specifically, I have a .NET MVC project that uses Razor for the markup. I want to make some ajax calls and update parts of the UI without using JQuery. Instead, I ...

Troubleshooting a CSS problem within mat-autocomplete component in Angular 7

While using mat-autocomplete, I noticed that when I select an option from the dropdown and then scroll through the main bar, the dropdown menu does not move along with the autocomplete input field. view image here Here is the code snippet: <td width ...

Create a versatile multi-autocomplete-chips input in Angular 9 using FormArray and encounter the issue: ERROR TypeError: control.registerOnChange is not a

Current Situation Table component - a table with buttons to create or edit rows. Clicking on any of these buttons will open the same Dialog component containing an input field. The input field is a reusable multi-autocomplete-chips component. If the user ...

Devextreme experiences the submission of multiple forms simultaneously

While working with Devextreme forms in Angular 2, I encountered an issue with two separate forms. Whenever I click the submit button on either the first or second form, both forms undergo validation. Why is this happening? https://i.sstatic.net/1orrY.png ...

What steps are needed for an Angular application to connect to a database using a local server?

We are currently developing an application that utilizes Angular for the front-end, Spring Boot for the middle layer, and a MySQL database for the back-end. At the moment, the front-end directly communicates with the Apache Tomcat server to access the data ...

Retrieve the specified data stored within the ngValue attribute of an Angular 4 component

I am currently working on an Angular 4 project and I have a requirement to extract the value of the selected option from a dropdown menu in my component. Specifically, I am trying to retrieve the value of policyType.id, which is stored in the [ngValue] att ...

Tips for converting an online HTML document into a string within an Angular framework

I'm currently facing an issue while trying to extract data from an online HTML document using Angular. The problem lies in encountering a cors error consistently. Here is the snippet of my code for reading the HTML document: loadParsingData(htmlToP ...

Utilizing the menu in Angular7 to trigger a route switch is successful; however, attempting to copy and paste a route always redirects to

After closely comparing my angular6 project with another one, I have noticed the only difference is the use of 'sidenav' navigation. I have tried keeping the router-outlet in the app.component inside the sidenav container and also moved it to the ...

What is the best way to deliver a downloaded document to a client using NodeJS Express?

I am facing an issue with downloading files from my FTP server using a button on my front-end website. The FTP server is password protected, and only I as the admin have access to the password. However, when the user clicks the download button, the file ge ...

Any ideas for handling ProtractorJS timeouts while clicking an element?

The Issue at Hand I am currently facing a challenge with clicking a straightforward 'New Booking' button in my Angular 5 Material 2 Application. The code snippet for the button is as follows: <button _ngcontent-c9="" class="mat-menu-item" ma ...

Limiting the number of characters in a PrimeNG Quill editor

I am currently working on implementing a maximum length for the editor. Here is the code snippet I am using: this.editorTextChange$$ = this.quillEditor.onTextChange.asObservable() .subscribe((ev) => { const limit = this.maxLength; // last cha ...

Troubleshooting the issue with mocking the useTranslation function for i18n in JEST

Currently, I am facing an issue with my react component that utilizes translations from i18next. Despite trying to create tests for it using JEST, nothing seems to be getting translated. I attempted to mock the useTranslation function as shown below: cons ...

How the addition of a type union allows it to be assigned to AnyAction

Struggling with Redux code, I've encountered a peculiar behavior regarding type assignment that has left me puzzled. In the following code snippet, it's clear that you cannot assign anyaction to iaction. Yet, surprisingly, assigning anyaction to ...

"Discover a new approach to incorporating the ChangeDetectorRef service into your pipe functions

I am facing an issue while trying to inject the ChangeDetectorRef service into my custom pipe in Angular. The error I am encountering is: No provider for ChangeDetectorRef! Although I have looked at various examples related to similar functionalities (suc ...

Oh no! It seems like the build script is missing in the NPM

https://i.stack.imgur.com/el7zM.jpg npm ERR! missing script: build; I find it strange, what could be causing this issue? Any suggestions? I have included the fullstack error with the package.json. Please also review the build.sh code below. Fullstack err ...

Exploring the functionality of Angular Material Paginator in conjunction with Observables, esch

(Issue still unresolved) I am currently following guidance from both this stackoverflow post(using mat-card) and this one(using observable) to address my problem. My goal is to utilize *ngFor with mat-card to display an array of objects coming from an obs ...

Issue with Next.js: Callback function not being executed upon form submission

Within my Next.js module, I have a form that is coded in the following manner: <form onSubmit = {() => { async() => await requestCertificate(id) .then(async resp => await resp.json()) .then(data => console.log(data)) .catch(err => console ...

How can I apply concatMap in Angular?

Can you please guide me on how to effectively utilize concatMap with getPrices() and getDetails()? export class HistoricalPricesComponent implements OnInit, OnDestroy { private unsubscribe$ = new Subject < void > (); infoTitle ...