When trying to render my application in Jest to do some integration testing, I get the following error:
TypeError: Cannot read property 'createNode' of undefined
at AnimatedParam.createNode [as __nativeInitialize] (node_modules/react-native-reanimated/src/core/AnimatedNode.js:126:24)
at AnimatedParam.__nativeInitialize [as __attach] (node_modules/react-native-reanimated/src/core/AnimatedNode.js:71:10)
at new __attach (node_modules/react-native-reanimated/src/core/AnimatedParam.js:11:10)
at createAnimatedParam (node_modules/react-native-reanimated/src/core/AnimatedParam.js:71:10)
at createAnimatedFunction (node_modules/react-native-reanimated/src/core/AnimatedFunction.js:38:17)
at Object.<anonymous> (node_modules/react-native-reanimated/src/derived/interpolate.js:17:39)
The code it is complaining about in react-native-reanimated
looks like this:
__nativeInitialize() {
if (!this.__initialized) {
ReanimatedModule.createNode(this.__nodeID, { ...this.__nodeConfig });
this.__initialized = true;
}
}
And ReanimatedModule
is a type alias for NativeModule
from the react-native
library. Beyond that, I have not found any useful information that helps solve this issue.
What is particularly strange here is that I am not directly using react-native-reanimated
in my code base, and the only library components I can find that are using it are not being rendered in the components being tested, as far as I can tell.
I have not been able to slim down my code in any reasonable manner to reproduce this issue, and the code in question is protected by corporate copyrights, so I cannot share the repository. I will keep trying to reproduce the error in a small example, but I wanted to get this question out there in case anyone has any experience with this issue.
/node_modules/react-native-reanimated/src/reanimated2/mock.ts:6 import { ReduceMotion, SensorType } from './commonTypes'; ^^^^^^ SyntaxError: Cannot use import statement outside a module at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14) at Object.<anonymous> (node_modules/react-native-reanimated/mock.js:12:22)
– Alcoholize