-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
升级taro最新版1.3.20后编译报错 #4637
Comments
欢迎提交 Issue~ 如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏 如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。 Good luck and happy coding~ |
CC @nanjingboy |
1.3.21也有这个问题, 暂时先降级到原来版本 |
@jijingsong |
|
Hello~ 您的问题所提供的信息不足,我们无法定位到具体的问题。如果有空的话还请拔冗提供更具体的信息,否则这个 issue 将在 15 天后被自动关闭。 如果您在这 15 天中更新更多信息自动关闭的流程会自动取消,如有其他问题也可以发起新的 Issue。 Good luck and happy coding~ |
@jijingsong 麻烦 |
|
@jijingsong 大佬,还是不能复现,还是提供一个可重现的 demo 吧 |
@nanjingboy 我这边复现出来了
import { observable } from "mobx";
class TestStore {
@observable a = 1;
}
const store = {
test: new TestStore()
};
export default store;
import Taro, { Component, Config } from "@tarojs/taro";
import { View, Text } from "@tarojs/components";
import "./index.scss";
import { inject, observer } from "@tarojs/mobx";
@inject("test")
@observer
export default class Index extends Component {
/**
* 指定config的类型声明为: Taro.Config
*
* 由于 typescript 对于 object 类型推导只能推出 Key 的基本类型
* 对于像 navigationBarTextStyle: 'black' 这样的推导出的类型是 string
* 提示和声明 navigationBarTextStyle: 'black' | 'white' 类型冲突, 需要显示声明类型
*/
config: Config = {
navigationBarTitleText: "首页"
};
componentWillMount() {}
componentDidMount() {}
componentWillUnmount() {}
componentDidShow() {
const {
test: { a }
} = this.props;
console.log(a);
}
componentDidHide() {}
render() {
const { a } = this.props.test;
return (
<View className="index">
<Text>{a}</Text>
</View>
);
}
}
结果: index.esm.js?eb04:2478 TypeError: Cannot read property 'a' of undefined
at WrappedComponent.componentDidShow (index.js?7a4d:21)
at tryToCall (index.esm.js?eb04:2326)
at WrappedComponent.newComponentDidShow [as componentDidShow] (index.esm.js?eb04:2356)
at tryToCall (index.esm.js?eb04:2326)
at WrappedComponent.componentDidMount (index.esm.js?eb04:2369)
at eval (index.esm.js?eb37:1872)
at errorCatcher (index.esm.js?eb37:1742)
at eval (index.esm.js?eb37:1871)
at Array.forEach (<anonymous>)
at flushMount (index.esm.js?eb37:1867) 源代码: |
@nauxchen 已修复,下个版本更新后就可以了 |
那是什么原因导致的呢?下个版本大概什么时候更新? |
@jijingsong 不知道你遇到的 下版本更新也就是这几天吧。 |
Hello~ 您的问题楼上已经提供了解决方案,如果没有更多的问题这个 issue 将在 15 天后被自动关闭。 如果您在这 15 天中更新更多信息自动关闭的流程会自动取消,如有其他问题也可以发起新的 Issue。 Good luck and happy coding~ |
现阶段有什么解决办法吗,降级么 |
1.3.22貌似还是有这个问题 |
Hello~ 您的问题楼上已经提供了解决方案,如果没有更多的问题这个 issue 将在 15 天后被自动关闭。 如果您在这 15 天中更新更多信息自动关闭的流程会自动取消,如有其他问题也可以发起新的 Issue。 Good luck and happy coding~ |
issue贴的部分源码 @Inject('mainStore')
@Observer
class Message extends Component {
config = {
navigationBarTitleText: '订单'
}
constructor() {
super()
} 我的理解我这边之前碰到过一个props传递不正确的小问题,解决方法就是正确传入props。
这里仅仅说明我的理解哈,可能不准确。 当然,还有另一种解释,ES6的constructor是必须要super(props)的,只不过Taro更加严格。 |
当然我出现问题的场景是redux的store,我是觉得原理可能类似。 |
问题描述
升级最新版后,mobx store无法注入,打印出props显示为空,在1.2.X版本时无报错
复现步骤
1.基于mobx搭建项目
2. 从1.2.26升级到1.3.20,taro update self,taro update project
3. 为页面组件增加inject注解
4.启动,编译报错, TypeError: Cannot read property xxx of undefined
import Taro, { Component } from '@tarojs/taro'
import { observer, inject } from '@tarojs/mobx'
import { View, Text, Image } from '@tarojs/components';
import { AtIcon } from 'taro-ui'
import './index.scss'
@Inject('mainStore')
@observer
class Message extends Component {
config = {
navigationBarTitleText: '订单'
}
constructor() {
super()
}
getStore() {
console.log(this.props,'this.props')
return this.props.mainStore.messageStore
}
render() {
return (
)
}
}
export default Message
期望行为
[这里请用简洁清晰的语言描述你期望的行为]
编译不报错
报错信息
TypeError: Cannot read property 'messageStore' of undefined
at Injector.getStore (index.js:59)
at Injector._createData (index.js:106)
at Injector.target._createData (index.js:213)
at Object.createComponent (index.js:2583)
at index.js:171
at require (WAService.js:1)
at :164:7
at HTMLScriptElement.scriptLoaded (appservice?t=1571651896485:2363)
at HTMLScriptElement.script.onload (appservice?t=1571651896485:2375)
系统信息
补充信息
[可选]
[根据你的调查研究,出现这个问题的原因可能在哪里?]
The text was updated successfully, but these errors were encountered: