Cannot find module 'angular-in-memory-web-api'

祝高超
2023-12-01

在《Angular官方教程第七课HTTP》调试示例出现Cannot find module 'angular-in-memory-web-api'

分析问题

估计是缺少angular-in-memory-web-api依赖包,到工程根目录下的node_modules文件夹下去寻找angular-in-memory-web-api没有找到。

解决问题

  1. 查看工程根目录下的package.json,没有添加angular-in-memory-web-api,于是在”dependencies”下添加"angular-in-memory-web-api": "^0.3.2"

    {
      "name": "angular-tour-of-heroes",
      "version": "0.0.0",
      "license": "MIT",
      "scripts": {
        "ng": "ng",
        "start": "ng serve",
        "build": "ng build",
        "test": "ng test",
        "lint": "ng lint",
        "e2e": "ng e2e"
      },
      "private": true,
      "dependencies": {
        "@angular/animations": "^4.0.0",
        "@angular/common": "^4.0.0",
        "@angular/compiler": "^4.0.0",
        "@angular/core": "^4.0.0",
        "@angular/forms": "^4.0.0",
        "@angular/http": "^4.0.0",
        "@angular/platform-browser": "^4.0.0",
        "@angular/platform-browser-dynamic": "^4.0.0",
        "@angular/router": "^4.0.0",
        "core-js": "^2.4.1",
        "rxjs": "^5.1.0",
        "zone.js": "^0.8.4",
      },
      "devDependencies": {
        "@angular/cli": "1.1.1",
        "@angular/compiler-cli": "^4.0.0",
        "@angular/language-service": "^4.0.0",
        "@types/jasmine": "2.5.45",
        "@types/node": "~6.0.60",
        "codelyzer": "~3.0.1",
        "jasmine-core": "~2.6.2",
        "jasmine-spec-reporter": "~4.1.0",
        "karma": "~1.7.0",
        "karma-chrome-launcher": "~2.1.1",
        "karma-cli": "~1.0.1",
        "karma-jasmine": "~1.1.0",
        "karma-jasmine-html-reporter": "^0.2.2",
        "karma-coverage-istanbul-reporter": "^1.2.1",
        "protractor": "~5.1.2",
        "ts-node": "~3.0.4",
        "tslint": "~5.3.2",
        "typescript": "~2.3.3"
      }
    }
  2. 然后在项目根目录下执行cnpm install安装angular-in-memory-web-api依赖。

  3. 然后重新执行npm start

 类似资料: