我已經創建了當我嘗試和應用程序訪問的入口點頁,其中遇到了以下錯誤的簡單的NodeJS/Angular2應用:router_1.provideRouter不是試圖運行時函數Angular2 /應用程序的NodeJS
router_1.provideRouter is not a function
我不確定這個錯誤的含義,也不知道從哪裏開始。有沒有人有任何見解或想法,爲什麼這可能會發生?這是我的package.json文件(我想這可能是一些做的角包一個)
{
"name": "udemy-nodejs-angular2",
"version": "1.0.0",
"private": true,
"scripts": {
"start": "concurrently tsc -w && nodemon ./bin/www",
"vendor": "gulp vendor",
"gulp": "npm run vendor && gulp",
"postinstall": "typings install",
"typings": "typings"
},
"dependencies": {
"@angular/common": "^2.0.0-rc.2",
"@angular/compiler": "^2.0.0-rc.2",
"@angular/core": "^2.0.0-rc.2",
"@angular/http": "2.0.0-rc.2",
"@angular/platform-browser": "^2.0.0-rc.2",
"@angular/platform-browser-dynamic": "^2.0.0-rc.2",
"@angular/router": "3.0.0-beta.2",
"@angular/upgrade": "2.0.0-rc.2",
"body-parser": "~1.13.2",
"cookie-parser": "~1.3.5",
"debug": "~2.2.0",
"es6-shim": "^0.35.0",
"express": "~4.13.1",
"hbs": "~3.1.0",
"morgan": "~1.6.1",
"reflect-metadata": "^0.1.3",
"rxjs": "^5.0.0-beta.6",
"serve-favicon": "~2.3.0",
"systemjs": "0.19.27",
"zone.js": "^0.6.12"
},
"devDependencies": {
"concurrently": "^2.2.0",
"gulp": "^3.9.0",
"gulp-sourcemaps": "^1.6.0",
"gulp-typescript": "^2.10.0",
"nodemon": "^1.9.2",
"typings": "^0.8.1"
}
}
和我SystemJS配置:
// map tells the System loader where to look for things
var map = {
'app': 'js/app', // 'dist',
'rxjs': 'js/vendor/rxjs',
'@angular': 'js/vendor/@angular'
};
// packages tells the System loader how to load when no filename and/or no extension
var packages = {
'app': {main: 'boot.js', defaultExtension: 'js'},
'rxjs': {defaultExtension: 'js'}
};
var packageNames = [
'@angular/common',
'@angular/compiler',
'@angular/core',
'@angular/http',
'@angular/platform-browser',
'@angular/platform-browser-dynamic',
'@angular/router',
'@angular/testing',
'@angular/upgrade'
];
// add package entries for angular packages in the form '@angular/common': { main: 'index.js', defaultExtension: 'js' }
packageNames.forEach(function (pkgName) {
packages[pkgName] = {main: 'index.js', defaultExtension: 'js'};
});
var config = {
map: map,
packages: packages
};
System.config(config);
這裏有我的地方使用路由器的功能:
app.routes.ts
import {provideRouter, RouterConfig} from '@angular/router';
import {LoginComponent} from "./components/login/login.component";
import {DashboardComponent} from "./components/dashboard/dashboard.component";
export const routes: RouterConfig = [
{ path: 'login', component: LoginComponent },
{ path: 'dashboard', component: DashboardComponent }
];
export const APP_ROUTER_PROVIDERS = [
provideRouter(routes)
];
boot.ts:
import {bootstrap} from '@angular/platform-browser-dynamic';
import {AppComponent} from "./app.component";
import { APP_ROUTER_PROVIDERS } from './app.routes';
bootstrap(AppComponent, [
APP_ROUTER_PROVIDERS
])
.catch(err => console.error(err));
app.component.ts
import { Component } from '@angular/core';
import { ROUTER_DIRECTIVES } from '@angular/router';
@Component({
moduleId: module.id,
selector: 'my-app',
templateUrl: 'app.template.html',
directives: [
ROUTER_DIRECTIVES
]
})
export class AppComponent {
}
感謝
可以請你添加你的systemjs配置嗎?這很可能是'@ angular/router'-package的缺失配置 – Dinistro
我忘記了要使用'provideRouter'函數的代碼 – Dinistro
當然,我已將我的SystemJS配置添加到原始問題中 – devoncrazylegs