RxJs and Typescript. TS2307: Cannot find module '@reactivex/rxjs'

Alejandro Nanez picture Alejandro Nanez · Mar 12, 2017 · Viewed 21.4k times · Source

I got a problem with typescript and RxJs v5.

Please Look the UPDATE sections.

I did yarn add @reactivex/rxjs (also yarn add rxjs) and on my index.ts did import Rx from '@reactivex/rxjs'; and got this error: VSCode Error

Also, if I run node ./node_modules/.bin/tsc I got this error back too error TS2307: Cannot find module '@reactivex/rxjs'.

UPDATE

Also doing

import { Observable } from 'rxjs/Observable'

throws the same error enter image description here.

UPDATE 2

Well this seems to be more related to TS itself than to RxJS.

"compilerOptions": {
    "module": "commonjs",
    "allowJs": true,
    "outDir": "dist",
    "target": "es2015",
    "noImplicitAny": true,
    "noEmit": true,
    "strictNullChecks": true,
    "suppressExcessPropertyErrors": false,
    "suppressImplicitAnyIndexErrors": false,
    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "lib": [
        "es2015",
        "dom"
    ]
}

Having this ^ configuration seems to fix the VSCode issues, but running tsc against src/index.ts doesn't work

node_modules/rxjs/Observable.d.ts(69,60): error TS2693: 'Promise' only refers to a type, but is being used as a value here.

Answer

Abhishek Chadha picture Abhishek Chadha · Jul 17, 2017

Try setting the "moduleResolution": "node" inside your compileOptions to specify module resolution strategy for TS.

npm install rxjs --save

and in your Typescript

import { Observable } from 'rxjs/Rx';

That fixed it for me.