react-native-worklets-core: In callInContext the function parameter is not a valid worklet and cannot be called between contexts or from/to JS from/to a context.
While using:
function RealApp() {
const fibonacci = (num: number): number => {
'worklet';
if (num <= 1) return 1;
return fibonacci(num - 1) + fibonacci(num - 2);
};
const worklet = Worklets.createRunInContextFn(fibonacci);
worklet(50).then(result => {
console.log(`Fibonacci of 50 is ${result}`);
});
}
I get:
In callInContext the function parameter is not a valid worklet and cannot be called between contexts or from/to JS from/to a context.
Running:
Expo: 49
Babel:
module.exports = function (api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
plugins: [
'nativewind/babel',
'module:react-native-dotenv',
'react-native-worklets-core/plugin',
'react-native-reanimated/plugin',
['@babel/plugin-transform-flow-strip-types', { loose: true }],
['@babel/plugin-proposal-private-methods', { loose: true }],
],
};
};
I did rebuild, prebuild, clean cache, clean pods, removed node modules reinstalled etc…
About this issue
- Original URL
- State: open
- Created 9 months ago
- Reactions: 3
- Comments: 15 (3 by maintainers)
Any update on this? I am experiencing the same error. For example my code is:
When I look at the logs I see:
Loading react-native-worklets-core… Worklets loaded successfully [Error: In callInContext the function parameter is not a valid worklet and cannot be called between contexts or from/to JS from/to a context.]
My issue above looks to have been caused by the fact that our repo was using an older version of
react-native-reanimated(^2.14.1). Upgrading this to the latest version (^3.7.2) has fixed this for me - hope this helps someone else too!@chrfalch yes I did 🙂 provided you’re talking about this step:
Same thing happening to me, with the simplest worklet possible - just immediately returning a string