语法错误:React Native“0.71.10”node_modules index.js 文件中的“get Animated(): {...$Diff<AnimatedModule, {default: any}>, ...Animated}”

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

在一个项目上工作,一切都在 ios 模拟器上构建,并且运行完美,然后我提交到 github 并开始重构以使我的代码更整洁,在尝试再次构建后我收到此错误。在错误开始出现之前,我尝试将所有更改恢复到稳定版本,但现在它不会消失。应用程序将构建,但捆绑失败:

语法错误:.../node_modules/react-native/index.js:意外的标记(240:19)

 238 |   // Include any types exported in the Animated module together with its default export, so
  239 |   // you can references types such as Animated.Numeric
> 240 |   get Animated(): {...$Diff<AnimatedModule, {default: any}>, ...Animated} {
      |                    ^
  241 |     // $FlowExpectedError[prop-missing]: we only return the default export, all other exports are types
  242 |     return require('./Libraries/Animated/Animated').default;
  243 |   },

不确定到底是什么原因造成的,我尝试注释掉 React Native 动画 API 的所有导入,错误仍然存在,尝试删除 node_modules 并重新安装,错误仍然存在。确实在努力解决可能导致此问题的原因,并且它严重减慢了开发速度,我们将非常感谢任何帮助。

package.json:

{
  "name": "app_name",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start --reset-cache",
    "test": "jest"
  },
  "dependencies": {
    "@babel/plugin-transform-typescript": "^7.22.5",
    "@react-native-async-storage/async-storage": "^1.18.2",
    "@react-native-masked-view/masked-view": "^0.2.9",
    "@react-navigation/drawer": "^6.6.3",
    "@react-navigation/native": "^6.1.6",
    "@react-navigation/stack": "^6.3.16",
    "@stripe/stripe-react-native": "^0.28.0",
    "babel-preset-react-native": "^2.1.0",
    "react": "18.2.0",
    "react-native": "0.71.10",
    "react-native-gesture-handler": "^2.12.0",
    "react-native-reanimated": "^3.3.0",
    "react-native-safe-area-context": "^4.5.3",
    "react-native-screens": "^3.21.1",
    "react-native-toast-message": "^2.1.6",
    "react-native-vector-icons": "^9.2.0",
    "socket.io-client": "^4.6.2"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native-community/eslint-config": "^3.2.0",
    "@tsconfig/react-native": "^2.0.2",
    "@types/jest": "^29.2.1",
    "@types/react": "^18.0.24",
    "@types/react-native-vector-icons": "^6.4.13",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.2.1",
    "eslint": "^8.19.0",
    "jest": "^29.2.1",
    "metro-react-native-babel-preset": "0.73.9",
    "prettier": "^2.4.1",
    "react-test-renderer": "18.2.0",
    "typescript": "4.8.4"
  },
  "jest": {
    "preset": "react-native"
  }
}

Babel.config.js:

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    '@babel/plugin-transform-typescript',
    'react-native-reanimated/plugin',
  ],
};

metro.config.js:

/**
 * Metro configuration for React Native
 * https://github.com/facebook/react-native
 *
 * @format
 */

module.exports = {
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: true,
      },
    }),
  },
};

“react-native info”的输出:

System:
    OS: macOS 12.5.1
    CPU: (8) x64 Apple M2
    Memory: 45.67 MB / 8.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 18.16.0 - /usr/local/bin/node
    Yarn: Not Found
    npm: 9.5.1 - /usr/local/bin/npm
    Watchman: 2023.05.22.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.12.1 - /Users/ctb/.rvm/gems/ruby-2.7.6/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1
    Android SDK:
      API Levels: 27, 28, 29, 30
      Build Tools: 28.0.3, 30.0.0, 30.0.2
      System Images: android-30 | Google Play Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: Not Found
    Xcode: 14.2/14C18 - /usr/bin/xcodebuild
  Languages:
    Java: javac 17 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.2.0 => 18.2.0 
    react-native: 0.71.10 => 0.71.10 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

我希望应用程序至少能够打开,没有任何错误,卡在 ios 模拟器的错误屏幕上。发生的就是这个错误:

Error Message on App

react-native animation syntax-error node-modules
1个回答
0
投票

检查您是否从“react-native-reanimated”导入;不要从react-native-animable导入,

当前react-native-animable, 预期的 反应本机复活

© www.soinside.com 2019 - 2024. All rights reserved.