react-native-reanimated: Reanimated2: exception in useAnimatedStyle
Description
Exception inside useAnimatedStyle
function while trying to call Object.values
on updater._closure
:
TypeError: Cannot convert undefined value to object
Screenshots
Package versions
- Platform: Android (not tested on iOS)
- React: 16.13.1
- React Native: 0.63.2
- React Native Reanimated: 2.0.0-alpha.5
- Hermes: 0.5.2-rc1
- Babel config:
module.exports = {
plugins: [
['@babel/plugin-proposal-decorators', {legacy: true}],
'@babel/plugin-proposal-export-namespace-from',
['babel-plugin-module-resolver', {root: 'src'}],
'react-native-reanimated/plugin',
],
presets: ['module:metro-react-native-babel-preset'],
}
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 26 (11 by maintainers)
Did you try to run metro with reset cache?
I have the same problem, I’ve followed all the guides I could find, did everything here, still keeps breaking ```TypeError: Cannot convert undefined or null to object at Function.values (<anonymous>)
I saw this like 5 times already. All the fixes were cache.
If you’re trying to use “useAnimatedStyle” working on storybook web. You may have to write “worklet” at the top of the passed function.
For my case, it happened because babel couldn’t perceive directive literal of useAnimatedStyle, which, I guess, should have been automatically added when I use the hook.
As a result, react-native-reanimated/plugin couldn’t work as supposed. This lines of code are supposed to find our codes (which we applied useAnimatedStyle) and process ‘woklet’ part.
So, the simple solution, which doesn’t feel right, is to write “worklet” at the top of the passed function of useAnimatedStyle. So that, reanimated babel plugin can perceive the passed function wth directive.
Maybe it’s a problem of storybook’s default babel plugin. I suspect that one of babel plugin used in building storybook is blocking reanimated worklet to be injected in a right way.
this is not fixed/closed yet, I too getting the same issue
yarn start --reset-cache
didn’t help mebable.config.js:
Versions:
App runs fine if I comment the
useAnimatedStyle
callI was able to resolve the babel issues by changing my babel.config.js to .babelrc.json as follows:
I think this might have been a bit of a project specific case. However, I am starting to have issues with storybook(where I will open a ticket on their end). But I got a spring example to work on web!
This error occurs because
useAnimatedStyle
expectsworklet
as an argument (ref) andreact-native-reanimated/plugin
is supposed to convert the passed argument toworklet
automatically (ref). But if the passed function didn’t get converted into aworklet
due to any reason above error shows. For example directive will not work in cljs project.Above error is only shown in the older version, like
2.1.0
,2.2.0
, etc. newer versions don’t show errors due to this check, but the app just crashes with these logsI think there should also be an exported method for creating
worklet
instead of only relying on the directive. The method which currently exists is not completely implemented and is being removed in https://github.com/software-mansion/react-native-reanimated/pull/3254 PR.Please don’t remove the method and fix its implementation. Thank you cc: @piaskowyk
this doesn’t work for me.
I’m using reanimated@2.2.0 in react-native project. I tried everything I could, like reset cache, watchman clean cache, etc… It’s still not working.
@monthem could you please open a new issue regarding storybook?
babel plugin should handle all the default hooks. looks like storybook’s babel plugin messes around with the hooks names and reanimated plugin can’t detect them since worklet this is still working.
yarn start --reset-cache
run this code, it worked for me
refrens: https://docs.swmansion.com/react-native-reanimated/docs/next/troubleshooting/