React Native语法错误:意外的令牌,期望}

10

突然出现了一个错误Unexpected token, expected },没有明确的原因。

enter image description here

第136行第7个字符正是它说master: {的位置。

const styles = StyleSheet.create({
 master: {
  flex: 1,
  justifyContent: 'center',
  flexDirection: 'row',
  alignItems: 'center',
  flexWrap: 'wrap'
 }
});

之前它一直运行良好。我已经尝试过:

rm -rf node_modules && npm install
npm start -- --reset-cache

两者都没有变化。

3个回答

8

这个错误是由于我的渲染方法缺少了</>标签导致的。


2
你能解释一下吗?当我添加样式时,我遇到了相同的问题...但是如果我添加内联样式,那就没问题了。 - carinlynchin

1
在我的情况下,错误是
意外的令牌,期望“,”
原因在样式表中,使用 = 代替 :
color = colors.white 而不是 color: colors.white

0
在我的情况下,ComponentDidUpdate 方法是在 render() 方法之后执行的。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接