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

Failed to find module: "@angular/router/common_router_providers" error with angular router upgrade

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

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;
} 

知道我做错了什么吗?

更新:

我正在使用-

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

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

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

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

具有完全相同的行为。目前唯一的解决方法似乎是在版本 3.0.0-alpha.7

上保留 @angular/router