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

前端 未结 29 2169
青春惊慌失措
青春惊慌失措 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 07:01

    For me just doing an install from angular-tour-of-heroes directory works for me

    C:\nodejs\angular-tour-of-heroes>npm install angular-in-memory-web-api --save

    0 讨论(0)
  • 2020-11-29 07:02

    Try adding the typescript definitions:

    sudo typings install --save file:./node_modules/angular2-in-memory-web-api/in-memory-backend.service.d.ts
    

    ... specifying the dependency name:

    angular2-in-memory-web-api
    

    Then add the entry point for "angular2-in-memory-web-api" in /systemjs.config.js

    var packages = {
      ...
      'angular2-in-memory-web-api': { main: 'core.js', defaultExtension: 'js' }
    };
    
    0 讨论(0)
  • 2020-11-29 07:03

    From your root folder (the folder contain package.json), using:

    npm install angular-in-memory-web-api –-save
    
    0 讨论(0)
  • 2020-11-29 07:03

    For users who generated an empty project with angular cli 1.4.9 (Actual on October 2017) and then started follow the instructions step-by-step, just run the following command:

    npm i angular-in-memory-web-api
    

    Just that command, without anything additional.

    Hope that saves someone's time

    0 讨论(0)
  • 2020-11-29 07:04

    Latest fix as of this date, is to

    1. replace all instances of "angular2-in-memory-web-api" with "angular-in-memory-web-api".
    2. Change package.json dependency version from "angular-in-memory-web-api": "0.0.20" to "angular-in-memory-web-api": "0.1.0" and "zone.js": "^0.6.23" to "zone.js": "^0.6.25"
    3. In systemjs.config.js, change the path for index.js. It should look like:
      'angular-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' }
    0 讨论(0)
提交回复
热议问题