美文网首页
使用Mobx装饰器:Support for the experi

使用Mobx装饰器:Support for the experi

作者: SunnyLYummy | 来源:发表于2022-09-23 18:00 被阅读0次

Support for the experimental syntax 'decorators' isn't currently enabled (13:1):
解决方法:
1、需要添加两个库:
npx yarn add @babel/plugin-proposal-class-properties
npx yarn add @babel/plugin-proposal-decorators
2、在项目的根目录下,修改babel.config.js文件

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    'react-native-reanimated/plugin',
    ['@babel/plugin-proposal-decorators', { legacy: true }],
    ["@babel/plugin-proposal-class-properties", { loose: false }],
  ]
};

加了之后运行可能还会报错” TypeError: Cannot read property 'getItem' of undefined “,
https://github.com/facebook/react-native/issues/29084
需要添加新插件:
npx yarn add @babel/plugin-transform-flow-strip-types --dev,
继续修改babel.config.js文件

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    ['@babel/plugin-transform-flow-strip-types'],
    ['@babel/plugin-proposal-decorators', { legacy: true }], // must in front of class-properties
    ["@babel/plugin-proposal-class-properties", { loose: false }],
  ],
};

大功告成!

相关文章

网友评论

      本文标题:使用Mobx装饰器:Support for the experi

      本文链接:https://www.haomeiwen.com/subject/qfvnortx.html