Cannot find module 'rxjs-compat/Observable'

AngularRxjs

Angular Problem Overview


I am currently upgrading angular 4 to angular 6 code. I have installed "rxjs": "^6.3.2" and un-installed rxjs-compact as I have migrated the code to use the new rxjs operators. I am still getting the following errors. Dont know the reason why

ERROR in [at-loader] ./node_modules/rxjs/BehaviorSubject.d.ts:1:15
    TS2307: Cannot find module 'rxjs-compat/BehaviorSubject'.

ERROR in [at-loader] ./node_modules/rxjs/Observable.d.ts:1:15
    TS2307: Cannot find module 'rxjs-compat/Observable'.

ERROR in [at-loader] ./node_modules/rxjs/Observer.d.ts:1:15
    TS2307: Cannot find module 'rxjs-compat/Observer'.

ERROR in [at-loader] ./node_modules/rxjs/Operator.d.ts:1:15
    TS2307: Cannot find module 'rxjs-compat/Operator'.

ERROR in [at-loader] ./node_modules/rxjs/Subject.d.ts:1:15
    TS2307: Cannot find module 'rxjs-compat/Subject'.

ERROR in [at-loader] ./node_modules/rxjs/Subscription.d.ts:1:15
    TS2307: Cannot find module 'rxjs-compat/Subscription'.

Angular Solutions


Solution 1 - Angular

This will solve the issue:

npm install --save rxjs-compat 

See this GitHub issue

Edit : as per 10th October 2019 ,you can use below syntax as the earlier or the above one was a workaround.

import { Observable } from 'rxjs/Observable';

Reference doc: https://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.md#dropping-the-compatibility-layer

Solution 2 - Angular

None of these answers are correct. Installing rxjs-compat is just a workaround. All you have to do is correct the imports. Use:

import { Observable } from 'rxjs';

Instead of:

import { Observable } from 'rxjs/Observable';

This last import is supposed to go away when they finally decide to kill rxjs-compat (hopefully very soon)... so heads up! you need to update your code!!

Solution 3 - Angular

As, Jandro Rojas, already said, installing rxjs-compat dependency it's only a temporary walkaround. In the future, you still need to fix that. The best solution is to use an Angular update guide https://update.angular.io/ because of some mistakes can be fixed automatically.

From my experience with errors "Cannot find module 'rxjs-compat/Observable'", "Cannot find module 'rxjs-compat'" and etc.

  • You should fix all the imports. From:

import { Observable } from 'rxjs/Observable'

To:

import { Observable } from 'rxjs'

  • Check carefully your dependencies, it should be updated too to use the newest RxJs. In my case "ngx-bootstrap" was outdated.

Solution 4 - Angular

npm install --save rxjs-compat

and run the server again with ng serve

This works for me.

Solution 5 - Angular

Just open command prompt & add below command in to your root folder.

npm i rxjs-compat

Hope it's working ..

Solution 6 - Angular

import { Observable } from 'rxjs';

this will be enough, there's no need for other imports

Solution 7 - Angular

  • ] node_modules/rxjs/Observable.d.ts(1,15): error TS2307: Cannot find module 'rxjs-compat/Observable'

I have got same above error, to resolve the issue enter this command in you CLI:

  • npm install --save rxjs-compat

Then after import: import { Observable } from 'rxjs';

Solution 8 - Angular

Those who have this error while creating a salesforce project in VSCode, should ensure that the command - npm install [email protected] --save && npm install [email protected] --save

are installed in - C:\Program Files\Salesforce CLI\client\node_modules directory

Solution 9 - Angular

It worked for me just by replacing 'rxjs/Subscription' with 'rxjs'

Solution 10 - Angular

It looks like rxjs-compat is missing. just do

npm i rxjs-compat 

npm install

Solution 11 - Angular

Both the rxjs and rxjs-compat of the version 6.3.2 worked for me.

npm install rxjs@6.3.2 --save  &&  npm install rxjs-compat@6.3.2 --save

Solution 12 - Angular

npm i rxjs-compat

It's working for me.

Solution 13 - Angular

npm install --save rxjs-compat

import { Observable } from 'rxjs'

run server ng serve worked for Me

Solution 14 - Angular

npm uninstall @ngrx/store

npm install @ngrx/[email protected]

npm install --save rxjs-compat

Solution 15 - Angular

in package.json add dependency "rxjs": "^6.5.4" then yarn install

or yarn add rxjs@^6.5.4

Solution 16 - Angular

I am using Angular 10,this method works for me.

npm install --save rxjs-compat

you should import observable this way:-

import { Observable } from 'rxjs/Observable';

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTomView Question on Stackoverflow
Solution 1 - AngularHameed SyedView Answer on Stackoverflow
Solution 2 - AngularJandro RojasView Answer on Stackoverflow
Solution 3 - AngularmscmncView Answer on Stackoverflow
Solution 4 - AngularAman GuptaView Answer on Stackoverflow
Solution 5 - AngularYogesh KumarView Answer on Stackoverflow
Solution 6 - AngularFeras DarkazanlyView Answer on Stackoverflow
Solution 7 - AngularAbdullahView Answer on Stackoverflow
Solution 8 - AngularManoj BhagwatView Answer on Stackoverflow
Solution 9 - AngularWissam Al ShohofView Answer on Stackoverflow
Solution 10 - AngularF.AhmadView Answer on Stackoverflow
Solution 11 - AngularNimesh ShahView Answer on Stackoverflow
Solution 12 - AngularParidhi shahView Answer on Stackoverflow
Solution 13 - AngularabhinavxeonView Answer on Stackoverflow
Solution 14 - AngularMohammad IrshadView Answer on Stackoverflow
Solution 15 - AngularPiyush JindalView Answer on Stackoverflow
Solution 16 - Angularchander lal piterView Answer on Stackoverflow