2016-07-08 36 views
1

我已經創建了當我嘗試和應用程序訪問的入口點頁,其中遇到了以下錯誤的簡單的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 { 

} 

感謝

+0

可以請你添加你的systemjs配置嗎?這很可能是'@ angular/router'-package的缺失配置 – Dinistro

+0

我忘記了要使用'provideRouter'函數的代碼 – Dinistro

+1

當然,我已將我的SystemJS配置添加到原始問題中 – devoncrazylegs

回答

1

正如我們在聊天發現,該問題是在供應商文件夾中的路由器沒有得到更新到新版。

要解決此問題,必須刪除供應商文件夾下的路由器,然後運行npm install,最後使用npm run gulp重新創建供應商文件夾。

+1

我可以證實這一點。雖然我正在將路由器更新到package.json中的最新版本。我沒有通過運行Gulp文件來更新供應商文件夾。 – devoncrazylegs

相關問題