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

HttpClientInMemoryWebApiModule has http-backend.service dependency #215

Open

Description

@pauleustice

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.

Activity

  1. SamJBarney commented on Nov 29, 2018

    @SamJBarney

    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.

  2. BStephenBB commented on Dec 4, 2018

    @BStephenBB

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

  3. hieundx commented on Dec 4, 2018

    @hieundx

    @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

  4. robsoncloud commented on Dec 11, 2018

    @robsoncloud

    same here

  5. vishal423 commented on Dec 11, 2018

    @vishal423
    Contributor

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

  6. JudeMag commented on Jan 22, 2019

    @JudeMag

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

  7. KostyaTretyak commented on Jan 22, 2019

    @KostyaTretyak
    npm r angular-in-memory-web-api
    npm i -D angular-in-memory-web-api
  8. SuperITMan commented on Jul 16, 2019

    @SuperITMan

    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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions