使用Mobx装饰器:Support for the experi

2022-09-23  本文已影响0人  SunnyLYummy

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 }],
  ],
};

大功告成!

上一篇 下一篇

猜你喜欢

热点阅读