错误:[bundle failed:'InMemoryBackendService'不是由node_modules \ angular2-in-memory-web-api \ index.js导出的 (由src \ app \ app.module.ts导入)。有关修复此错误的帮助,请参阅https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module]
前 app.ts
import "reflect-metadata";
import {XHRBackend} from '@angular/http';
import {InMemoryBackendService} from 'angular2-in-memory-web-api';
import {HTTP_PROVIDERS} from '@angular/http';
import {Component} from '@angular/core';
import {ionicBootstrap} from 'ionic-angular';
import {SplashPage} from './pages/splash/splash';
@Component({
template: '<ion-nav [root]="rootPage"></ion-nav>',
providers: []
})
export class MyApp {
rootPage: any = SplashPage;
constructor(
) {}
}
ionicBootstrap(
MyApp,
[
HTTP_PROVIDERS,
{provide: XHRBackend, useClass: InMemoryBackendService}
]
);
后 app.module.ts
import { NgModule } from '@angular/core';
import { IonicApp, IonicModule } from 'ionic-angular';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import {InMemoryBackendService} from 'angular2-in-memory-web-api';
import {XHRBackend} from '@angular/http';
import {HttpModule} from '@angular/http';
import {ServerConfig} from '../server-config';
@NgModule({
declarations: [
MyApp,
HomePage,
],
imports: [
IonicModule.forRoot(MyApp),
HttpModule
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
providers: [
{provide: XHRBackend, useClass: InMemoryBackendService}
]
})
export class AppModule {}
答案 0 :(得分:0)
对我来说,解决方案是在app文件夹中创建一个名为 in-memory-backend.service.ts 的新文件,其中包含以下内容:
//import { OpaqueToken } from '@angular/core';
//import { Headers, Request, Response, ResponseOptions } from '@angular/http';
//import { Observable } from 'rxjs/Observable';
//import 'rxjs/add/operator/delay';
///**
//* Seed data for in-memory database`enter code here`
//* Must implement InMemoryDbService.
//*/
//export declare const SEED_DATA: OpaqueToken;
///**
//* Interface for a class that creates an in-memory database
//* Safe for consuming service to morph arrays and objects.
//*/
//export interface InMemoryDbService {
// /**
// * Creates "database" object hash whose keys are collection names
// * and whose values are arrays of the collection objects.
// *
// * It must be safe to call again and should return new arrays with new objects.
// * This condition allows InMemoryBackendService to morph the arrays and objects
// * without touching the original source data.
// */
// createDb(): {};
//}
///**
//* Interface for InMemoryBackend configuration options
//*/
//export interface InMemoryBackendConfigArgs {
// /**
// * default response options
// */
// defaultResponseOptions?: ResponseOptions;
// /**
// * delay (in ms) to simulate latency
// */
// delay?: number;
// /**
// * false (default) if ok when object-to-delete not found; else 404
// */
// delete404?: boolean;
// /**
// * host for this service
// */
// host?: string;
// /**
// * root path before any API call
// */
// rootPath?: string;
//}
///**
//* InMemoryBackendService configuration options
//* Usage:
//* provide(InMemoryBackendConfig, {useValue: {delay:600}}),
//*/
//export declare class InMemoryBackendConfig implements InMemoryBackendConfigArgs {
// constructor(config?: InMemoryBackendConfigArgs);
//}
///**
//* Interface for object w/ info about the current request url
//* extracted from an Http Request
//*/
//export interface ReqInfo {
// req: Request;
// base: string;
// collection: any[];
// collectionName: string;
// headers: Headers;
// id: any;
// resourceUrl: string;
//}
//export declare const isSuccess: (status: number) => boolean;
///**
// * Simulate the behavior of a RESTy web api
// * backed by the simple in-memory data store provided by the injected InMemoryDataService service.
// * Conforms mostly to behavior described here:
// * http://www.restapitutorial.com/lessons/httpmethods.html
// *
// * ### Usage
// *
// * Create InMemoryDataService class the implements IInMemoryDataService.
// * Register both this service and the seed data as in:
// * ```
// * // other imports
// * import { HTTP_PROVIDERS, XHRBackend } from 'angular2/http';
// * import { InMemoryBackendConfig, InMemoryBackendService, SEED_DATA } from '../in-memory-backend/in-memory-backend.service';
// * import { InMemoryStoryService } from '../api/in-memory-story.service';
// *
// * @Component({
// * selector: ...,
// * templateUrl: ...,
// * providers: [
// * HTTP_PROVIDERS,
// * provide(XHRBackend, { useClass: InMemoryBackendService }),
// * provide(SEED_DATA, { useClass: InMemoryStoryService }),
// * provide(InMemoryBackendConfig, { useValue: { delay: 600 } }),
// * ]
// * })
// * export class AppComponent { ... }
// * ```
// */
//export declare class InMemoryBackendService {
// private _seedData;
// protected _config: InMemoryBackendConfigArgs;
// protected _db: {};
// constructor(_seedData: InMemoryDbService, config: InMemoryBackendConfigArgs);
// createConnection(req: Request): {
// response: Observable<{}>;
// };
// /**
// * Process Request and return an Http Response object
// * in the manner of a RESTy web api.
// *
// * Expect URI pattern in the form :base/:collectionName/:id?
// * Examples:
// * api/characters
// * api/characters/42
// * api/characters.json/42 // ignores the ".json"
// * commands/resetDb // resets the "database"
// */
// protected _handleRequest(req: Request): Response;
// protected _clone(data: any): any;
// /**
// * When the `base`="commands", the `collectionName` is the command
// * Example URLs:
// * commands/resetdb // Reset the "database" to its original state
// * commands/config (GET) // Return this service's config object
// * commands/config (!GET) // Update the config (e.g. delay)
// *
// * Usage:
// * http.post('commands/resetdb', null);
// * http.get('commands/config');
// * http.post('commands/config', '{"delay":1000}');
// */
// protected _commands(reqInfo: ReqInfo): ResponseOptions;
// protected _createErrorResponse(status: number, message: string): ResponseOptions;
// protected _delete({ id, collection, collectionName, headers }: ReqInfo): ResponseOptions;
// protected _findById(collection: any[], id: number): any;
// protected _genId(collection: any): any;
// protected _get({ id, collection, collectionName, headers }: ReqInfo): ResponseOptions;
// protected _getLocation(href: string): HTMLAnchorElement;
// protected _indexOf(collection: any[], id: number): number;
// protected _parseId(id: string): any;
// protected _parseUrl(url: string): {
// base: string;
// id: string;
// collectionName: string;
// resourceUrl: string;
// };
// protected _post({ collection, headers, id, req, resourceUrl }: ReqInfo): ResponseOptions;
// protected _put({ id, collection, collectionName, headers, req }: ReqInfo): ResponseOptions;
// protected _removeById(collection: any[], id: number): boolean;
// /**
// * Reset the "database" to its original state
// */
// protected _resetDb(): void;
// protected _setStatusText(options: ResponseOptions): ResponseOptions;
//}
然后在main.ts中为这个新创建的文件添加正确的路径。