Operators无法找到模块

Operators无法找到模块

本文介绍了Angular 7 CI rxjs/Operators无法找到模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已尝试按照以下配置使用Circle CI为我的角度项目设置CI: https://angular.io/guide/testing#configure-project-for-circle-ci

但是,当 ng测试运行时,出现以下错误:

src/app/account/login-form/login-form.component.ts(4,26)中的

  ERROR:错误TS2307:找不到模块'rxjs/Operators'. 

在本地,如果我删除 node_modules/并运行 npm install 然后执行 npm test ,则rxjs没问题./p>

我的 package.json :

 依赖项":{"@ angular/animations":"7.2.4","@ angular/common":"7.2.4","@ angular/compiler":"7.2.4","@ angular/core":"7.2.4","@ angular/forms":"7.2.4","@ angular/http":"7.2.4","@ angular/platform-b​​rowser":"7.2.4","@ angular/platform-b​​rowser-dynamic":"7.2.4","@ angular/platform-server":"7.2.4","@ angular/router":"7.2.4","@ ng-bootstrap/ng-bootstrap":"^ 4.0.2","@ nguniversal/module-map-ngfactory-loader":"7.1.0","angularx-social-login":"^ 1.2.6","aspnet-prerendering":"^ 3.0.1","bootstrap":"^ 4.2.1","core-js":"^ 2.5.4","rxjs":"^ 6.4.0","zone.js":"^ 0.8.29"},"devDependencies":{"@ angular-devkit/build-angular":〜0.13.0","@ angular/cli":〜7.3.0","@ angular/compiler-cli":"7.2.4","@ angular/language-service":"^ 7.2.4","@ types/茉莉花":〜2.8.6","@ types/jasminewd2":〜2.0.3","@ types/node":〜8.9.4","bootstrap-sass":"3.4.0","codelyzer":〜4.5.0",茉莉花芯":〜2.99.1","jasmine-spec-reporter":〜4.2.1","karma":"^ 3.0.0","karma-chrome-launcher":〜2.2.0",业力报废的伊斯坦布尔记者":〜1.4.2",业力茉莉花":〜1.1.1","karma-jasmine-html-reporter":"^ 0.2.2","typescript":〜3.2.4"},"optionalDependencies":{"node-sass":"4.11.0",量角器":〜5.4.0","ts-node":〜5.0.1","tslint":〜5.9.1"} 

login-form.component.ts 中的有害行:

  import {订阅};从'rxjs/Operators'导入{finalize}; 

我可以在这里提供任何有用的资源,但我不知道有什么用.

解决方案

那是因为您应该从 rxjs/operators 而不是 rxjs/Operators 导入.

I have tried setting up CI for my angular project using Circle CI following this configuration:https://angular.io/guide/testing#configure-project-for-circle-ci

However, when ng test runs I get the following error:

ERROR in src/app/account/login-form/login-form.component.ts(4,26): error TS2307: Cannot find module 'rxjs/Operators'.

Locally, if I delete node_modules/ and run npm install followed by npm test I don't have any issue with rxjs.

My package.json:

"dependencies": {
  "@angular/animations": "7.2.4",
  "@angular/common": "7.2.4",
  "@angular/compiler": "7.2.4",
  "@angular/core": "7.2.4",
  "@angular/forms": "7.2.4",
  "@angular/http": "7.2.4",
  "@angular/platform-browser": "7.2.4",
  "@angular/platform-browser-dynamic": "7.2.4",
  "@angular/platform-server": "7.2.4",
  "@angular/router": "7.2.4",
  "@ng-bootstrap/ng-bootstrap": "^4.0.2",
  "@nguniversal/module-map-ngfactory-loader": "7.1.0",
  "angularx-social-login": "^1.2.6",
  "aspnet-prerendering": "^3.0.1",
  "bootstrap": "^4.2.1",
  "core-js": "^2.5.4",
  "rxjs": "^6.4.0",
  "zone.js": "^0.8.29"
},
"devDependencies": {
  "@angular-devkit/build-angular": "~0.13.0",
  "@angular/cli": "~7.3.0",
  "@angular/compiler-cli": "7.2.4",
  "@angular/language-service": "^7.2.4",
  "@types/jasmine": "~2.8.6",
  "@types/jasminewd2": "~2.0.3",
  "@types/node": "~8.9.4",
  "bootstrap-sass": "3.4.0",
  "codelyzer": "~4.5.0",
  "jasmine-core": "~2.99.1",
  "jasmine-spec-reporter": "~4.2.1",
  "karma": "^3.0.0",
  "karma-chrome-launcher": "~2.2.0",
  "karma-coverage-istanbul-reporter": "~1.4.2",
  "karma-jasmine": "~1.1.1",
  "karma-jasmine-html-reporter": "^0.2.2",
  "typescript": "~3.2.4"
},
"optionalDependencies": {
  "node-sass": "4.11.0",
  "protractor": "~5.4.0",
  "ts-node": "~5.0.1",
  "tslint": "~5.9.1"
}

The offending lines in login-form.component.ts:

import { Subscription } from 'rxjs';
import { finalize } from 'rxjs/Operators';

I can provide any source on here that is helpful but I don't know what is relevant.

解决方案

That's because you should import from rxjs/operators, not rxjs/Operators.

这篇关于Angular 7 CI rxjs/Operators无法找到模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 00:17