Angular2 教程(英雄之旅):找不到模块“angular2-in-memory-web-api" [英] Angular2 Tutorial (Tour of Heroes): Cannot find module 'angular2-in-memory-web-api'

查看:31
本文介绍了Angular2 教程(英雄之旅):找不到模块“angular2-in-memory-web-api"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了教程.在 Http 章节中更改 app/maint.ts 后,通过命令行启动应用程序时出现错误:

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:

app/main.ts(5,51):错误 TS2307:找不到模块angular2-in-memory-web-api".

app/main.ts(5,51): error TS2307: Cannot find module 'angular2-in-memory-web-api'.

(Visual Studio Code 在 main.ts 中给了我同样的错误 - 红色波浪下划线.)

(Visual Studio Code gives me the same error within main.ts - red wavy underlining.)

这是我的systemjs.config.js:

/**
 * System configuration for Angular 2 samples
 * Adjust as necessary for your application needs.
 */
(function(global) {
  // map tells the System loader where to look for things
  var map = {
    'app':                        'app', // 'dist',
    '@angular':                   'node_modules/@angular',
    'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
    'rxjs':                       'node_modules/rxjs'
  };
  // packages tells the System loader how to load when no filename and/or no extension
  var packages = {
    'app':                        { main: 'main.js',  defaultExtension: 'js' },
    'rxjs':                       { defaultExtension: 'js' },
    'angular2-in-memory-web-api': { defaultExtension: 'js' },
  };
  var ngPackageNames = [
    'common',
    'compiler',
    'core',
    'http',
    'platform-browser',
    'platform-browser-dynamic',
    'router',
    'router-deprecated',
    'upgrade',
  ];
  // Add package entries for angular packages
  ngPackageNames.forEach(function(pkgName) {
    packages['@angular/'+pkgName] = { main: pkgName + '.umd.js', defaultExtension: 'js' };
  });
  var config = {
    map: map,
    packages: packages
  }
  System.config(config);
})(this);

这是我的app/main.ts:

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

import { InMemoryBackendService, SEED_DATA } from 'angular2-in-memory-web-api';
import { InMemoryDataService }               from './in-memory-data.service';

// The usual bootstrapping imports
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 }), // in-mem server
    provide(SEED_DATA,  { useClass: InMemoryDataService })     // in-mem server data
]);

推荐答案

对我来说唯一的解决方案是将 angular2-in-memory-web-api 升级到 0.0.10.

For me the only solution was to upgrade angular2-in-memory-web-api to 0.0.10.

package.json 中设置

'angular2-in-memory-web-api': '0.0.10'

在dependecies块中,并在systemjs.config.js set

in the dependecies block, and in systemjs.config.js set

'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' }

packages 对象中.

这篇关于Angular2 教程(英雄之旅):找不到模块“angular2-in-memory-web-api"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆