Angular2教程(英雄之旅):找不到模块'angular2-in-memory-web-api' [英] Angular2 Tutorial (Tour of Heroes): Cannot find module '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
set
'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' }
in packages
object。
in the packages
object.
这篇关于Angular2教程(英雄之旅):找不到模块'angular2-in-memory-web-api'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!