【问题标题】:Uncaught Error: Cannot find module - Ionic 2未捕获的错误:找不到模块 - Ionic 2
【发布时间】:2016-07-11 13:25:21
【问题描述】:

我正在处理 Ionic 2 项目,并将 rootPage 设置为 AuthPage。后来,我创建了另一个名为 SplashPage 的页面(通过控制台),但是当我将 rootPage 设置为 SplashPage 时,我遇到了错误Uncaught Error: Cannot find module "./pages/splash/splash" (app.bundle.js:3188)。有什么问题的线索吗?

app.ts

import {App, IonicApp, Platform} from 'ionic-angular';
import {ListPage} from './pages/list/list';
import {WishListPage} from './pages/wishlist/wishlist';
import {AuthPage} from './pages/auth/auth';
import {SplashPage} from './pages/splash/splash';

@App({
    templateUrl: 'build/app.html',
    config: {}, // http://ionicframework.com/docs/v2/api/config/Config/
    providers: [UserService]
})
class MyApp {
    rootPage: any = SplashPage;
    pages: Array<{title: string, component: any, user: string}>;
    user: any;
    constructor(private app: IonicApp, private platform: Platform,
                private userService: UserService) {
        this.initializeApp();
        this.user = userService;

        // used for an example of ngFor and navigation
        this.pages = [

            // No need to include this since the user shouldn't see
            // the login page again until their session/token expires
            //{ title: 'Login', component: AuthPage },

            // Since we don't need to fear our user manually navigating
            // via url, why not manage naviagtion permissions with simple
            // template conditionals `*ngIf`
            { title: 'Wishlist', component: WishListPage, user: "shopper"}, // SHOPPER
            { title: 'Current Orders', component: ListPage, user: "shopper" }, // SHOPPER
            { title: 'Orders', component: ListPage, user: "boxer" }, // BOXER
            { title: 'Profile', component: ProfilePage, user:"both" } // BOTH
        ];

    }

splash.ts

import {OnInit} from 'angular2/core';
import {NgIf} from 'angular2/common';
import {Page, NavController} from 'ionic-angular';

// @PAGES
import {AuthPage} from '../auth/auth';

@Page({
    templateUrl: 'build/pages/splash/splash.html',
    directives: [NgIf],
    providers: []
})

export class SplashPage {
    constructor() { console.log("@AuthPage: __init__"); }
}

【问题讨论】:

  • 找到了吗?同样的错误,谢谢
  • @AlejandroLora 还没有:/
  • 它可能没用,但请尝试使用 '@Component' 装饰器而不是 '@Page' 装饰器并告诉我们..

标签: typescript ionic2


【解决方案1】:

看起来像 app.ts 你正在调用类 spalsh 但实际的类名是 SplashPage

所以尝试,在#splash.ts 中将SplashPage 重命名为Splash

【讨论】:

  • 我怀疑这就是问题所在。否则,我不得不将类 AuthPage 重命名为 Auth 并将 WishListPage 重命名为 WishList (两者都工作正常)。顺便说一句,SplashPage 是通过命令 ionic g page splash 自动创建的
猜你喜欢
  • 2018-07-21
  • 2017-09-21
  • 2021-11-24
  • 2015-11-22
  • 2018-12-01
  • 1970-01-01
  • 2022-10-25
  • 2022-08-13
  • 2016-10-24
相关资源
最近更新 更多