RxJs 和打字稿.TS2307:找不到模块“@reactivex/rxjs" [英] RxJs and Typescript. TS2307: Cannot find module '@reactivex/rxjs'

查看:52
本文介绍了RxJs 和打字稿.TS2307:找不到模块“@reactivex/rxjs"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

打字稿和 RxJs v5 有问题.

I got a problem with typescript and RxJs v5.

我做了 yarn add @reactivex/rxjs(也yarn add rxjs)并且在我的 index.ts 上做了 import Rx from '@reactivex/rxjs'; 并得到这个错误:

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:

另外,如果我运行 node ./node_modules/.bin/tsc 我也得到这个错误 error TS2307: 找不到模块 '@reactivex/rxjs'.

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

也在做

import { Observable } from 'rxjs/Observable'

抛出相同错误.

好吧,这似乎与 TS 本身有关,而不是与 RxJS 相关.

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

拥有这个 ^ 配置似乎可以解决 VSCode 问题,但是针对 src/index.ts 运行 tsc 不起作用

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.

推荐答案

尝试在 compileOptions 中设置 "moduleResolution": "node" 来指定模块解析策略TS.

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

npm install rxjs --save

并在您的打字稿中

import { Observable } from 'rxjs/Rx';

那为我修好了.

这篇关于RxJs 和打字稿.TS2307:找不到模块“@reactivex/rxjs"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆