简体   繁体   中英

How to enable ES2020 in react-native app?

I was trying to add ES2020 features in my react-native app, I installed "babel-preset-es2020": "^1.0.2" and added .babelrc file like this:

{
  "presets": ["es2020"]
}

But nothing seems to work, this error is coming there:

error: Error: Unable to resolve module `./animations/TimingAnimation` from `node_modules\react-native-reanimated\src\Animated.js`:

None of these files exist:
  * node_modules\react-native-reanimated\src\animations\TimingAnimation(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)
  * node_modules\react-native-reanimated\src\animations\TimingAnimation\index(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)
    at ModuleResolver.resolveDependency (C:\Users\smond\dev\sg_app\node_modules\metro\src\node-haste\DependencyGraph\ModuleResolution.js:163:15)
    at ResolutionRequest.resolveDependency (C:\Users\smond\dev\sg_app\node_modules\metro\src\node-haste\DependencyGraph\ResolutionRequest.js:52:18)
    at DependencyGraph.resolveDependency (C:\Users\smond\dev\sg_app\node_modules\metro\src\node-haste\DependencyGraph.js:287:16)
    at Object.resolve (C:\Users\smond\dev\sg_app\node_modules\metro\src\lib\transformHelpers.js:267:42)
    at C:\Users\smond\dev\sg_app\node_modules\metro\src\DeltaBundler\traverseDependencies.js:434:31
    at Array.map (<anonymous>)
    at resolveDependencies (C:\Users\smond\dev\sg_app\node_modules\metro\src\DeltaBundler\traverseDependencies.js:431:18)
    at C:\Users\smond\dev\sg_app\node_modules\metro\src\DeltaBundler\traverseDependencies.js:275:33
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (C:\Users\smond\dev\sg_app\node_modules\metro\src\DeltaBundler\traverseDependencies.js:87:24)

Please tell me a way to enable ES2020 there

Your error appears to be related to react-native-reanimated package not ES version. Make sure that react-native-reanimated is installed at your package.json, else:

npm i react-native-reanimated

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM