Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

HttpClientInMemoryWebApiModule has http-backend.service dependency #215

Open
pauleustice opened this issue Sep 7, 2018 · 9 comments
Open

Comments

@pauleustice
Copy link

Hi, I've just tried using this module for the first time and ran into this issue:

Version: 0.6.1
Angular Version: 6

When trying to build, I receive this Typescript error, failing the build:

ERROR in node_modules/angular-in-memory-web-api/http-backend.service.d.ts(2,75): error TS2307: Cannot find module '@angular/http'

App module (cut down for brevity):

import { HttpClientInMemoryWebApiModule } from 'angular-in-memory-web-api';
import { MockApiService } from './services/mock-api.service';

@NgModule({
  declarations: [ AppComponent ],
  imports: [
    BrowserModule,
    HttpClientModule,
    environment.production ?
      [] : HttpClientInMemoryWebApiModule.forRoot(
      MockApiService, {
        dataEncapsulation: false,
        passThruUnknownUrl: false,
        put204: false // return entity after PUT/update
      }
    ),
  ]

MockApiService:

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

export class MockApiService implements InMemoryDbService {
  createDb() {
    const reports = [
      { id: 1, limit: 37},
      { id: 2, limit: 118 },
      { id: 3, limit: 93 },
    ];
    return {
      reports
    };
  }
}

As far as I can tell, if one is using the HttpClientInMemoryWebApiModule, there should be no dependencies on @angular/http. It's a simple fix to npm i it, but seems like a bug nonetheless.

@SamJBarney
Copy link

I am running on Angular 7, and am having the same problem. It seems like a small problem that a lot of new Angular people run into, and so if you're gonna keep the backwards compatibility, you should at least update the docs to explain to people how to resolve the issue.

@BStephenBB
Copy link

Just got the same error while going through the Angular docs for the first time too. Definitely confusing.

@hieundx
Copy link

hieundx commented Dec 4, 2018

@angular/http API is deprecated in favor of @angular/common/http. But changing the import source to @angular/common/http won't solve it bc the API doesn't export those in @angular/http
https://angular.io/api/http

@robsoncloud
Copy link

same here

@ghost
Copy link

ghost commented Dec 11, 2018

Doing an Angular 7 project and I too am facing this issue.
An ugly way of temporarily fixing it is to npm install @angular/http --save-dev
@wardbell should have a serious look into this.

@vishal423
Copy link
Contributor

I see many duplicate issues opened for same reason. Please do note a PR is already in progress to remove this dependency #223

@JudeMag
Copy link

JudeMag commented Jan 22, 2019

Hey Guys, give this a try
npm install angular-in-memory-web-api --save

@KostyaTretyak
Copy link

npm r angular-in-memory-web-api
npm i -D angular-in-memory-web-api

@SuperITMan
Copy link

Hey everyone,
For your info the issue has been solved with version 0.8.0: https://github.com/angular/in-memory-web-api/blob/master/CHANGELOG.md#080-2018-12-06 😊

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants