0

I would like to use angular2-in-memory-web-api but I get these errors :

GET http://localhost:3000/node_modules/angular2-in-memory-web-api/index.js.map 404 (Not Found)
GET http://localhost:3000/node_modules/angular2-in-memory-web-api/in-memory-backend.service.js.map 404 (Not Found)
GET http://localhost:3000/node_modules/angular2-in-memory-web-api/http-status-codes.js.map 404 (Not Found)

In the angular2-in-memory-web-api folder I have these files with extension .js and .d.ts but not .js.map

I read this Angular2 Tutorial (Tour of Heroes): Cannot find module 'angular2-in-memory-web-api' and test every solutions but it still doesn't work for me.

Here my code:

boot.ts :

// Imports for loading & configuring the in-memory web api
 import { provide }    from '@angular/core';
 import { XHRBackend } from '@angular/http';
 import 'rxjs/Rx';
 import 'rxjs/add/operator/map';

 import { InMemoryBackendService, SEED_DATA } from '../node_modules/angular2-in-memory-web-api';
 import { FavoriDataBase}               from './favori/favori-database';

 import { bootstrap }      from '@angular/platform-browser-dynamic';
 import { HTTP_PROVIDERS } from '@angular/http';
 import { AppComponent }   from './app.component';

 bootstrap(AppComponent, [
HTTP_PROVIDERS, 
provide(XHRBackend, { useClass: InMemoryBackendService }),
provide(SEED_DATA,  { useClass: FavoriDataBase })]);

In systemjs.config.js I have this line 'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' } And in package.json "angular2-in-memory-web-api": "0.0.10" I also updated angular2-in-memory-web-api in my console.

Everything worked find before I decide to use 'angular2-in-memory-web-api', I was using real http url to catch data and now I need to use "in folder url" to catch data of a created database (initially empty).

My database class:

export class FavoriDataBase {
createDb() {
let database= [];
return {database};
 }
}

Thanks by advance for any help !

2
  • Have you tried this? import { InMemoryBackendService, SEED_DATA } from 'angular2-in-memory-web-api'; Commented Jun 15, 2016 at 12:40
  • Yes, same problem... Commented Jun 15, 2016 at 12:43

2 Answers 2

0

It's a bug. Here's the issue. https://github.com/angular/in-memory-web-api/issues/7

Sign up to request clarification or add additional context in comments.

Comments

0

I had to explicitly specify the providers:

providers: [
    HTTP_PROVIDERS,
    appRoutingProviders,
    { provide: XHRBackend, useClass: InMemoryBackendService },
    { provide: SEED_DATA, useClass: MyData }
  ],

where MyData is the class containing your fake data.

The description of the in-memory-api in the quickstart docs didn't mention this, but it worked for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.