[英]Module not found: Error: Can't resolve 'rxjs/add/observable/throw'
I have the following imports in my " posts.service.ts " 我的“ posts.service.ts ”中有以下导入
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { NotFoundError } from '../commons/errors/not-found-error.errors';
import { AppErrors } from '../commons/errors/app-errors.errors';
import { Observable } from 'rxjs';
import { catchError } from 'rxjs/operators';
import 'rxjs/add/observable/throw';
I even checked the node_modules folder for 'rxjs/add/observable/throw' and it is available there. 我甚至检查了node_modules文件夹中的'rxjs / add / observable / throw',它在那里可用。 But I get a strange error as shown below during project compilation phase. 但是在项目编译阶段我得到了一个奇怪的错误,如下所示。
ERROR in ./src/app/services/posts.service.ts Module not found: Error: Can't resolve 'rxjs/add/observable/throw' in '/Users/gauthampughaz/Development/angular/practice/src/app/services' ./src/app/services/posts.service.ts中的错误找不到模块:错误:无法解析'/ Users / gauthampughaz / Development / angular / practice / src / app中的'rxjs / add / observable / throw' /服务'
ℹ 「wdm」: Failed to compile. ℹ「wdm」:编译失败。
Since RxJS 6 you should import "creation" methods directly from 'rxjs'
: 从RxJS 6开始,您应该直接从'rxjs'
导入“创建”方法:
import { throwError } from 'rxjs';
Just don't forget you need to have proper path maps set but if you're using angular-cli you don't need to worry about that. 只是不要忘记您需要设置正确的路径图,但如果您使用的是angular-cli,则无需担心。 For more details see: https://github.com/ReactiveX/rxjs/blob/6.2.0/doc/pipeable-operators.md#build-and-treeshaking 有关详细信息,请参阅: https : //github.com/ReactiveX/rxjs/blob/6.2.0/doc/pipeable-operators.md#build-and-treeshaking
_throw is now exported as throwError. _throw现在导出为throwError。
You can do something like this if you dont want to replace every instance of _throw. 如果你不想替换_throw的每个实例,你可以做这样的事情。 (don't recommend). (不推荐)。
import { throwError as _throw } from 'rxjs';
Or you can just change everywhere you use _throw to throwError 或者你可以随处改变你使用_throw到throwError的地方
See other breaking changes here: 在此处查看其他重大更改:
https://github.com/ReactiveX/rxjs/blob/master/CHANGELOG.md#breaking-changes-7 https://github.com/ReactiveX/rxjs/blob/master/CHANGELOG.md#breaking-changes-7
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.