加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angular 5(英雄之旅)教程:无法找到模块’@ angular-in-memory-w

发布时间:2020-12-17 17:29:56 所属栏目:安全 来源:网络整理
导读:我发现了一个类似的 question,但它是针对angular2答案中的命令似乎特定于angular2或告诉我运行相同的cmd,所以我在这里问这个问题. 我正在关注Angular 5英雄之旅tutorial在HTTP部分,我收到以下错误: Failed to compile. src/app/app.module.ts(13,48): error
我发现了一个类似的 question,但它是针对angular2&答案中的命令似乎特定于angular2或告诉我运行相同的cmd,所以我在这里问这个问题.

我正在关注Angular 5英雄之旅tutorial&在HTTP部分,我收到以下错误:

Failed to compile.

src/app/app.module.ts(13,48): error TS2307: Cannot find module ‘@angular-in-memory-web-api’.

运行cmd后,我收到了一些警告,但确认安装:

λ npm install angular-in-memory-web-api --save
npm WARN ajv-keywords@3.1.0 requires a peer of ajv@^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modulesfsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ angular-in-memory-web-api@0.5.3
added 1 package in 25.102s

我的package.json文件正确显示了依赖项:

{
  "name": "hello-world","version": "0.0.0","license": "MIT","scripts": {
    "ng": "ng","start": "ng serve","build": "ng build --prod","test": "ng test","lint": "ng lint","e2e": "ng e2e"
  },"private": true,"dependencies": {
    "@angular/animations": "^5.2.0","@angular/common": "^5.2.0","@angular/compiler": "^5.2.0","@angular/core": "^5.2.0","@angular/forms": "^5.2.0","@angular/http": "^5.2.0","@angular/platform-browser": "^5.2.0","@angular/platform-browser-dynamic": "^5.2.0","@angular/router": "^5.2.0","angular-in-memory-web-api": "^0.5.3","core-js": "^2.4.1","rxjs": "^5.5.6","zone.js": "^0.8.19"
  },"devDependencies": {
    "@angular/cli": "~1.7.0","@angular/compiler-cli": "^5.2.0","@angular/language-service": "^5.2.0","@types/jasmine": "~2.8.3","@types/jasminewd2": "~2.0.2","@types/node": "~6.0.60","codelyzer": "^4.0.1","jasmine-core": "~2.8.0","jasmine-spec-reporter": "~4.2.1","karma": "~2.0.0","karma-chrome-launcher": "~2.2.0","karma-coverage-istanbul-reporter": "^1.2.1","karma-jasmine": "~1.1.0","karma-jasmine-html-reporter": "^0.2.2","protractor": "~5.1.2","ts-node": "~4.1.0","tslint": "~5.9.1","typescript": "~2.5.3"
  }
}

app.module.ts文件:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms'; // <-- NgModel lives here
import { AppComponent } from './app.component';
import { HeroesComponent } from './heroes/heroes.component';
import { HeroDetailComponent } from './hero-detail/hero-detail.component';
import { HeroService } from './hero.service';
import { MessagesComponent } from './messages/messages.component';
import { MessageService } from './message.service';
import { AppRoutingModule } from './app-routing.module';
import { DashboardComponent } from './dashboard/dashboard.component';
import { HttpClientModule } from '@angular/common/http';
import { HttpClientInMemoryWebApiModule } from '@angular-in-memory-web-api';
import { InMemoryDataService } from './in-memory-data.service';


@NgModule({
  declarations: [
    AppComponent,HeroesComponent,HeroDetailComponent,MessagesComponent,DashboardComponent
  ],imports: [
    BrowserModule,FormsModule,AppRoutingModule,HttpClientModule,// The HttpClientInMemoryWebApiModule module intercepts HTTP requests
// and returns simulated server responses.
// Remove it when a real server is ready to receive requests.
HttpClientInMemoryWebApiModule.forRoot(
  InMemoryDataService,{ dataEncapsulation: false }
)
  ],providers: [HeroService,MessageService],bootstrap: [AppComponent]
})
export class AppModule { }

我试过重启VS代码&重新运行上面的cmd但它没有帮助.

解决方法

导入是错误的. @不是必需的.
替换为此

import { HttpClientInMemoryWebApiModule } from 'angular-in-memory-web-api';

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读