如何将`react-native-reanimated/plugin`添加到`babel.config.js`?

问题描述 投票:0回答:2

我正在尝试将

react-native-reanimated
v1.13.3
升级到
v2.0.1
。在安装说明中,他们说将
react-native-reanimated/plugin
添加到您的
babel.config.js
,如下所示:

  module.exports = {
    presets: [
      ...
    ],
    plugins: [
      ...
      'react-native-reanimated/plugin',
    ],
  };

目前我的

babel.config.js
看起来像这样:

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  env: {
    production: {
      plugins: [
        'react-native-paper/babel'
      ],
    },
  }
};

如果我这样添加:

plugins: [
            'react-native-paper/babel'
            'react-native-reanimated/plugin'
          ],

我收到此错误:

Transform's input file does not exist: <project>/node_modules/react-native-reanimated/android/react-native-reanimated-65.aar. (See https://issuetracker.google.com/issues/158753935)

我应该如何添加它?

reactjs react-native babeljs react-native-reanimated react-native-reanimated-v2
2个回答
3
投票

你可以尝试:

module.exports = {
   presets: ['module:metro-react-native-babel-preset'],
   env: {
      production: {
         plugins: [
           'react-native-paper/babel'
         ],
      },
   },
   plugins: [
        'react-native-reanimated/plugin',
   ],
};

0
投票

phuocantd 的功能有效,但是在将react-native-reanimated/plugin 添加到 babel.js 脚本后,您还需要清除缓存。我在构建项目时与 Expo 合作,可以通过首先停止 expo 服务器并运行以下命令来清除缓存:

npx expo start -c
© www.soinside.com 2019 - 2024. All rights reserved.