Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

微信小程序入口文件改为HOOKS函数式组件导致生成的app.json内容为空对象,无法运行 #4641

Closed
xiajun325 opened this issue Oct 21, 2019 · 4 comments
Labels
question Further information is requested

Comments

@xiajun325
Copy link

问题描述
微信小程序入口app.jsx由类组件形式改为函数式组件
导致生成的app.json内容为空对象

复现步骤
1.将app入口改为HOOKS函数式组件
2.声明config改为App.config = { ...}
3. yarn dev:weapp
4. 编译后生成app.json 为 { } , 导致无法运行小程序

//app.jsx
export default function App() {
      return (
        <Index />
     )
}

  App.config = {
        pages: [
          'pages/index/index'
        ],
        window: {
          backgroundTextStyle: 'light',
          navigationBarBackgroundColor: '#fff',
          navigationBarTitleText: 'WeChat',
          navigationBarTextStyle: 'black'
        }
      }

期望行为
可以正常运行

报错信息
VM1758:1 appJSON["pages"] 字段需为 array
console.error @ VM1758:1
(anonymous) @ VM1771:2

系统信息
👽 Taro v1.3.20
Taro CLI 1.3.20 environment info:
System:
OS: macOS High Sierra 10.13
Shell: 5.3 - /bin/zsh
Binaries:
Node: 10.16.3 - /usr/local/bin/node
Yarn: 1.19.1 - /usr/local/bin/yarn
npm: 6.9.0 - /usr/local/bin/npm

补充信息
问题原因:
在 mini/astProcess.js 中

 else if (node.id.name === 'App') {
                        componentClassName = '_App';  //这里类名改为_App
  
......
 if (left.object.name === componentClassName // 这里比较时用的是 App, 所以不等
                    && t.isIdentifier(left.property)
                    && left.property.name === 'config') {
                    needSetConfigFromHooks = true;
                    configFromHooks = node.right;

经验证,将App.config= ... 改为_App.config = ... 就可以了

@taro-bot
Copy link

taro-bot bot commented Oct 21, 2019

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@luckyadam
Copy link
Member

app 不能改成 hook

@luckyadam luckyadam added answered question Further information is requested labels Oct 22, 2019
@taro-bot
Copy link

taro-bot bot commented Oct 22, 2019

Hello~

您的问题楼上已经有了确切的回答,如果没有更多的问题这个 issue 将在 15 天后被自动关闭。

如果您在这 15 天中更新更多信息自动关闭的流程会自动取消,如有其他问题也可以发起新的 Issue。

Good luck and happy coding~

@saviourdog
Copy link

same shit

@taro-bot taro-bot bot removed the to be closed label Nov 6, 2019
@taro-bot taro-bot bot closed this as completed Nov 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants