RxJs va Typescript. TS2307: "@ reactivex/rxjs" moduli topilmadi

Rasski va RxJs v5 bilan muammo chiqdi.

Iltimos, UPDATE bo'limlariga qarang.

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

Bundan tashqari

import { Observable } from 'rxjs/Observable'

bir xil xatosini chiqaradi .

UPDATE 2

Xo'sh, bu RXJSga qaraganda TSning o'zi bilan ko'proq bog'liq.

"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"
    ]
}

Ushbu ^ konfiguratsiyaga ega bo'lish VSCode muammolarini tuzatishga o'xshaydi, lekin src/index.ts ga qarshi ishlaydigan tsc ishlamaydi

node_modules/rxjs/Observable.d.ts(69,60): error TS2693: 'Promise' only refers to a type, but is being used as a value here.
4
Men shunchaki asbob-uskuna tushishiga shubha qilaman. package.json "main": "index.js" va "yozuvlar bilan biroz o'ziga xos emas:" ./dist/cjs/Rx. d.ts ". Ushbu vositalar typing usuli foydalanilmaydi. Yaxshiyamki, RxJS qaramligida boshqa biror narsa foydalanayotgan bo'lsangiz, boshqa dependencies uchun npm install rxjs ni o'rnatishingiz kerak.
qo'shib qo'ydi muallif cartant, manba
@ reactivex/rxjs tarkibida to'plami asosiy deb atalgan faylga parallel bo'lgan .d.ts fayl yo'q. json ; .d.ts yanada chuqur ichki o'rnatilgan. Menimcha, bu ba'zi vositalarni chalkashtirib yuborishi mumkin. Agar sizda rxjs ishlatadigan boshqa qaramliklar (masalan, burchaklar) mavjud bo'lsa, @ reactivex/rxjs da turlar turli xil ko'rinishda bo'lgani uchun, TypeScript odatda baxtsiz bo'lishi mumkin. Men Martinning javobiga borishni maslahat beraman.
qo'shib qo'ydi muallif cartant, manba
Hey Cartant, bir oz ko'proq iltimos qila olasizmi? Men sizni bu erda kuzatmayapman deb o'ylayman.
qo'shib qo'ydi muallif Alejandro Nanez, manba

6 javoblar

TS uchun modul o'lchamlari strategiyasini belgilash uchun compileOptions ichida "moduleResolution": "tugunni" ni o'rnatishni harakat qilib ko'ring.

npm o'rnatish rxjs --save

va sizning Kindiginizda

"Rxjs/Rx" dan import {Observable};

Bu men uchun belgilangan.

6
qo'shib qo'ydi
Nima uchun bu muammo yuzaga keldi? Bu faqat rxjslarni qayta o'rnatishni emas, chunki u allaqachon mavjud burchakli ilovalar uchun, lekin u bir xil xatolarni beradi
qo'shib qo'ydi muallif M98, manba

RxJS 5 uchun siz quyidagilarni ishlatishingiz kerak:

import * as Rx from 'rxjs';

Yoki kutubxonaning o'ziga xos qismini import qiling:

import { Observable } from 'rxjs/Observable';

For more info see: https://github.com/ReactiveX/rxjs/#installation-and-usage

2
qo'shib qo'ydi
Albatta, bu ./ node_modules/rxjs saytiga tushirilganligiga ishonchingiz komilmi?
qo'shib qo'ydi muallif martin, manba
Hey Martin minnatdorchilik, lekin men o'rnatish va foydalanish ostidagi narsalarni sinab ko'rdim. JS import {Observable} dan 'rxjs/Observable'; Yuqorida aytib o'tilganidek, "modul rxjs/Observable topilmadi"
qo'shib qo'ydi muallif Alejandro Nanez, manba
Ha, u erda.
qo'shib qo'ydi muallif Alejandro Nanez, manba

Ushbu sintaksisini foydalaning:

impYokit { Observable } from 'rxjs/Rx'

Yoki

impYokit Rx from 'rxjs/Rx';
Rx.Observable.of(1,2,3)

Yoki

impYokit { Observable} from 'rxjs/Observable';
impYokit 'rxjs/add/observable/of';
impYokit 'rxjs/add/operatYoki/map';

Observable.of(1,2,3).map(x => x + '!!!');//etc

All these examples can be found on the website: http://reactivex.io/rxjs/manual/installation.html

0
qo'shib qo'ydi

npm install rxjs ni amalga oshirgan Visual Studio 2017da yangi "Salom Dunyo" loyihasi bilan bir xil muammoga duch keldim.

Asosan, bu mening server.ts faylida mavjud edi:

import { Observable } from 'rxjs/Observable'
import * as http from 'http';

var port = process.env.port || 1337
http.createServer(function (req, res) {
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end('Hello World\n');
}).listen(port);

Derleme imkoniyatlari moduli va lib uchun belgilangan qiymatlarga qarab, bu xato yuzaga keldi:

server.ts(1,28): error TS2307: Build:Cannot find module 'rxjs/Observable'.

yoki:

node_modules\rxjs\Observable.d.ts(73,59): error TS2693: Build:'Promise' only refers to a type, but is being used as a value here.

Men uchun ishlaydigan kompilyatsiya variantlarining qozongan kombinatsiyasi quyidagilar edi:

"compilerOptions": {
    "module": "commonjs",
    "lib": [ "es2015" ]
  }

Bu ikkala xato ham ketishdi.

0
qo'shib qo'ydi
This is a hard nut to crack: my fix

 in package.json  dependencies confirm this code exists:

     "rxjs": "^5.5.2",


In file /node_modules/@angular/core/src/application_ref.d.ts

//import { Observable } from 'rxjs/Observable';
// yeah, sure, I'm not supposed to, but I did and i worked
   import { Observable } from 'rxjs/Rx';


in file node_modules/rxjs/src/tsconfig.json

    {
      "compilerOptions": {
        "removeComments": false,
        "preserveConstEnums": true,
        "sourceMap": true,
        "declaration": true,
        "noImplicitAny": true,
        "noImplicitReturns": true,
        "noImplicitThis": true,
        "suppressImplicitAnyIndexErrors": true,
        "moduleResolution": "node",
        "target": "es6",
        "outDir": "dist/es6",
        "lib": [ "es2016.array.include" ]
      },
      "formatCodeOptions": {
        "indentSize": 2,
        "tabSize": 2
      },
      "bazelOptions": {
        "suppressTsconfigOverrideWarnings": true
      },
      "files": [
        "src/Rx.ts"
      ]
    }

for this ng --version

    Angular CLI: 1.6.7
    Node: 8.11.1
    OS: darwin x64
    Angular: 5.2.10
    ... animations, common, compiler, compiler-cli, core, forms
    ... http, language-service, platform-browser
    ... platform-browser-dynamic, router

    @angular/cli: 1.6.7
    @angular-devkit/build-optimizer: 0.0.42
    @angular-devkit/core: 0.0.29
    @angular-devkit/schematics: 0.2.0
    @ngtools/json-schema: 1.1.0
    @ngtools/webpack: 1.9.7
    @schematics/angular: 0.1.17
    typescript: 2.4.2
    webpack-dev-server: 2.11.2
    webpack: 3.10.0
0
qo'shib qo'ydi

For me I had the error below:
error TS2307: Cannot find module 'rxjs-compat/Observable'.

Solution: instead of importing:
import { Observable } from 'rxjs/Observable';
use: import { Observable } form 'rxjs';

and you can put to the observable you want to import by separating all by comma like:
import { Observable, of } form 'rxjs';

0
qo'shib qo'ydi