无法找到模块:角度路由器升级时出现“@ angular / router / common_router_providers”错误

时间:2016-07-10 17:34:21

标签: angularjs angular nativescript

我正在尝试升级我的nativescript应用程序以使用新的Angular Router,但是,我收到以下错误消息:

java.lang.RuntimeException: Unable to create application com.tns.NativeScriptApplication: com.tns.NativeScriptException: Failed to find module: "@angular/router/common_router_providers", relative to: /app/tns_modules/
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4710)
    at android.app.ActivityThread.-wrap1(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5417)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: com.tns.NativeScriptException: Failed to find module: "@angular/router/common_router_providers", relative to: /app/tns_modules/
    at com.tns.Module.resolvePathHelper(Module.java:220)
    at com.tns.Module.resolvePath(Module.

在我的main.ts我有:

import {nativeScriptBootstrap} from "nativescript-angular/application";
import {AppComponent} from "./app.component";
import {APP_ROUTER_PROVIDERS} from "./app.routes";

nativeScriptBootstrap(AppComponent, [APP_ROUTER_PROVIDERS]);

然后在我的app.routes.ts我有:

import {RouterConfig} from '@angular/router';
import {nsProvideRouter} from "nativescript-angular/router";
import {HomePage} from "./Components/Home/home.component";
import {Bottles} from "./Components/BottleList/bottleList.component";

const routes: RouterConfig = [
    { path: "", redirectTo: "/home", terminal: true },
    { path: "home", component: HomePage },
    { path: "bottles", component: Bottles },
];

export const APP_ROUTER_PROVIDERS = [
    nsProvideRouter(routes, {enableTracing: false })
];

然后我的app.component.ts

import {Component, OnInit} from "@angular/core";
import {NS_ROUTER_DIRECTIVES} from "nativescript-angular/router";

@Component({
  selector: "main",
  directives: [NS_ROUTER_DIRECTIVES],
  template: "<page-router-outlet></page-router-outlet>"
})

export class AppComponent implements OnInit {
  page: Page;
} 

任何想法我做错了什么?

更新

我正在使用 -

  • tns-android: 2.1.1
  • @ angular / common: 2.0.0-rc.4
  • @ angular / router: 3.0.0-beta.2
  • nativescript-angular: 0.2.0
  • tns-core-modules: 2.1.0
  • nativescript(global): 2.1.1
  • node(global): 4.4.7

3 个答案:

答案 0 :(得分:2)

我找到了一些东西,但它只是一种解决方法:使用angular2组件的所有rc3版本(路由器(3.0.0-alpha.7除外)和路由器弃用(2.0.0-rc.2除外) )), 有用。但您也需要在文件中添加一些更改(请查看here

答案 1 :(得分:1)

我上周从@angular/router": "3.0.0-alpha.7升级到@angular/router-deprecated": "2.0.0-rc.2并成功升级。

看看这个 NativeScript / sample-Groceries 分支https://github.com/NativeScript/sample-Groceries/tree/angular-v3-router它有rc3升级提交。

同时删除平台&amp;全局 tns_modules 文件夹和升级(删除并安装) tns 可能会解决您的问题。

答案 2 :(得分:0)

具有完全相同的行为。目前唯一的解决方法似乎是将.ToDictionary( item => item, item => (IReadOnlyCollection<T>) relatedItemsSelector(item) .ToList() .AsReadOnly() // Didn't expect to need the direct cast ) 留在版本3.0.0-alpha.7