如何解决 Ionic Uncaught Error: 找不到模块“."添加新页面时?

编程入门 行业动态 更新时间:2024-10-21 14:29:16
本文介绍了如何解决 Ionic Uncaught Error: 找不到模块“."添加新页面时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

未捕获的错误:找不到模块."

Uncaught Error: Cannot find module "."

    at webpackMissingModule (index.js:3)
    at e.code (index.js:3)
    at Object.<anonymous> (index.js:9)
    at __webpack_require__ (bootstrap ee3a374a94c4cd74e2a6:54)
    at Object.256 (main.ts:5)
    at __webpack_require__ (bootstrap ee3a374a94c4cd74e2a6:54)
    at Object.233 (main.js:412)
    at __webpack_require__ (bootstrap ee3a374a94c4cd74e2a6:54)
    at webpackJsonpCallback (bootstrap ee3a374a94c4cd74e2a6:25)
    at main.js:1

在应用程序中添加新的 bookmarks 页面之前,应用程序运行良好,添加 bookmarks 页面后,我收到 未捕获的错误:找不到模块."

Before adding new bookmarks pages in app, the app working perfectly fine, After adding bookmarks pages i'm getting Uncaught Error: Cannot find module "."

这是我的设置

Ionic Framework: 3.9.2
Angular Core: 5.2.11
Angular Compiler CLI: 5.2.11
Node: 8.11.1

app.module.ts

import { ContactPage } from '../pages/contact/contact';
import { BookmarksPage} from'../pages/bookmarks/bookmarks';

@NgModule({
  declarations: [
    ContactPage,
    BookmarksPage,
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    ContactPage,
    BookmarksPage,
  ],
  providers: [
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
    ]
  })
export class AppModule {}

bookmarks.ts

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';

@Component({
selector: 'page-bookmarks',
templateUrl: 'bookmarks.html'
 })
export class BookmarksPage {
    constructor(public navCtrl: NavController) {
  }
}

开发者控制台中的 index.js

我也尝试清除缓存和 npm rebuild.在构建 (ionic serve) 过程中没有错误.但是在浏览器中我发现找不到模块,我真的很想了解这里发生了什么

I've tried to clear cache and npm rebuild also. In the build (ionic serve) process there is no errors. But in the browser i'm getting Cannot find module, i really want to understand what is going on here

推荐答案

终于发现,当从 ionic cli 创建项目时,项目中缺少 IonicPageModule.

Finally figured out, when creating the project from ionic cli the IonicPageModule was missing on the project.

在项目中手动添加 IonicPageModule 并运行命令 npm run-script 修复了问题.

Adding IonicPageModule manually in project and running command npm run-script fixed the issue.

解决方案

app-module.ts

import { IonicPageModule } from 'ionic-angular';

imports: [
  IonicPageModule.forChild(HomePage)
],

npm run-script build

注意:IonicPageModule 是一个 NgModule,它引导子 IonicPage 以设置路由.

NOTE: IonicPageModule is an NgModule that bootstraps a child IonicPage in order to set up routing.

PS:仍然不知道那是如何工作的,但那是有效的.感谢大家的帮助.

PS: Still dint know how that worked, but that worked. Thanks everyone for trying to help.

这篇关于如何解决 Ionic Uncaught Error: 找不到模块“."添加新页面时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-22 16:46:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1027008.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:找不到   如何解决   模块   新页面   Ionic

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!