> 文档中心 > A page must have one and only one ‘@Entry‘ decorator with a struct.【BUG已解决】

A page must have one and only one ‘@Entry‘ decorator with a struct.【BUG已解决】

文章目录

  • 项目场景:
  • 问题描述
  • 原因分析:
  • 解决方案:

项目场景:

在学习基于OpenHarmony/HarmonyOS操作系统的ArkUI框架的过程中,使用DevEco Studio 3.0.0.993打开一个小的Demo的过程中。
打开Previewer的时候爆出如下错误:

mpile Result] A page configured in ‘config.json’ must have one and only one ‘@Entry’ decorator.
[Compile Result] Compile error occurred. Fix it based on the above message.

报错页面1:
A page must have one and only one ‘@Entry‘ decorator with a struct.【BUG已解决】
报错页面2:
A page must have one and only one ‘@Entry‘ decorator with a struct.【BUG已解决】

问题描述

出现如下报错:
mpile Result] A page configured in ‘config.json’ must have one and only one ‘@Entry’ decorator.
Compile Result] Compile error occurred. Fix it based on the above message.

我的项目目录结构:
A page must have one and only one ‘@Entry‘ decorator with a struct.【BUG已解决】

原因分析:

翻译结果:
在“config”中配置的页面。json’必须且只能有一个’@Entry’装饰器。
在config.json中“pages” : [ 配置了该文件 ],导致编译器认为此文件是页面,必须加修饰器@Entry。
发生编译错误。根据上面的消息修复它。

解决方案:

检查index.ets的文件开头是否引用了装饰器:@Entry。
A page must have one and only one ‘@Entry‘ decorator with a struct.【BUG已解决】

import Myinput from "../common/componets/myinput"@Entry@Componentstruct Index {  @State message: string = 'OpenHarmony'  @State username: string='1上进小菜猪23'  @State password: string='3241'  // @ts-ignore  private username_reg= /^[0-9a-zA-Z]{5,8}/;

改正后检测,是否成功:
A page must have one and only one ‘@Entry‘ decorator with a struct.【BUG已解决】
该BUG【A page must have one and only one ‘@Entry’ decorator with a struct】成功解决。