Angular2 Tutorial (Tour of Heroes): Cannot find module 'angular2-in-memory-web-api'

前端 未结 29 2295
青春惊慌失措
青春惊慌失措 2020-11-29 06:25

I have followed the Tutorial. After changing app/maint.ts in the Http chapter I get the error when starting the app via command line:

ap

29条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-29 06:52

    If you are using angular cli, you would get this error.

    Please add 'angular2-in-memory-web-api' in the const barrels in the system-config.ts file as below:

     const barrels: string[] = [
      // Angular specific barrels.
      '@angular/core',
      '@angular/common',
      '@angular/compiler',
      '@angular/forms',
      '@angular/http',
      '@angular/router',
      '@angular/platform-browser',
      '@angular/platform-browser-dynamic',
    
      // Thirdparty barrels.
      'rxjs',
      'angular2-in-memory-web-api',
    
      // App specific barrels.
      'app',
      'app/shared',
      /** @cli-barrel */
    ];
    

    And add 'angular2-in-memory-web-api': 'vendor/angular2-in-memory-web-api' as below.

    System.config({
      map: {
        '@angular': 'vendor/@angular',
        'rxjs': 'vendor/rxjs',
        'main': 'main.js',
        'angular2-in-memory-web-api': 'vendor/angular2-in-memory-web-api'
      },
      packages: cliSystemConfigPackages,
    
    });
    

    Rebuild using npm start. This resolved the issue for me.

提交回复
热议问题