Open mortenmo opened 4 months ago
Hey there, @mortenmo! š I'm here to help you with any bugs, questions, or contributions you have while you wait for a human maintainer. I'm a bot that can assist with all things related to the repository.
To resolve the initialization error "Cannot access 'computedOffsetXValueWithAutoFillData' before initialization" when starting up Metro after migrating to Expo 51, ensure that the function computedOffsetXValueWithAutoFillData
is properly defined and exported before it is used. The provided code snippet already shows the correct definition and export of the function.
Here is the relevant part of the code:
export function computedOffsetXValueWithAutoFillData(
params: BaseParams<{
rawDataLength: number
value: number
size: number
}>,
) {
"worklet";
const { rawDataLength, value, size, loop, autoFillData } = params;
if (isAutoFillData({ loop, autoFillData })) {
switch (rawDataLength) {
case SINGLE_ITEM:
return value % size;
case DOUBLE_ITEM:
return value % (size * 2);
}
}
return value;
}
Ensure that this function is not being referenced before its definition in your code. If the error persists, it might be due to a circular dependency or an import issue. Double-check your import statements and the order of your function definitions to ensure there are no circular dependencies [1].
To continue talking to Dosu, mention @dosu.
same
Having the same issue
+1
I wonder if this is related to Babel's config? The React Native Reanimated docs requires react-native-reanimated/plugin
to be added to the babel config to make worklets function properly. And I notice that computedOffsetXValueWithAutoFillData() uses a "worklet"
I'm using Expo and getting the same Metro error: Cannot access 'computedOffsetXValueWithAutoFillData' before initialization
error when running in the browser. I added the plugin to (turns out this is auto added via babel.config.js
, but still getting itbabel-preset-expo
Here are the default Expo package versions for reference:
Possible workaround: Add "@babel/plugin-transform-block-scoping"
to my babel.config.js
plugins list
Got this idea from this react-native-reanimated issue
I'd rather not need to add "@babel/plugin-transform-block-scoping"
to my plugin list just for this issue, but at least it seems to work š
Possible workaround: Add
"@babel/plugin-transform-block-scoping"
to mybabel.config.js
plugins listGot this idea from this react-native-reanimated issue
I'd rather not need to add
"@babel/plugin-transform-block-scoping"
to my plugin list just for this issue, but at least it seems to work š
This solution does not seem to work for me. I am using a Windows and using the Web version for testing.
I found the solution. As mentioned earlier, this issue is because of a circular dependency in react-native-gesture-handler
. I found the circular issue here. Which references another PR that solved the circular dependency.
The solution is to simply upgrade the react-native-gesture-handler
to the latest 2.18.1 by running
npm install --save react-native-gesture-handler@2.18.1
The solution is to simply upgrade the
react-native-gesture-handler
to the latest 2.18.1 by running
This doesn't seem to work for me, even after updating to react-native-gesture-handler 2.18.1. I also tried 2.19.0, still no luck.
The solution is to simply upgrade the
react-native-gesture-handler
to the latest 2.18.1 by runningThis doesn't seem to work for me, even after updating to react-native-gesture-handler 2.18.1. I also tried 2.19.0, still no luck.
Same here, tested 2.20.0 and no luck either
If you're using react-native-reanimated-carousel in an Expo project, you can try the following method:
First, customize the metro configuration by running npx expo customize metro.config.js
Then modify the code in the metro.config.js
file to the following:
/* eslint-env node */
// Learn more https://docs.expo.io/guides/customizing-metro
const { getDefaultConfig } = require('expo/metro-config');
const path = require('path');
/** @type {import('expo/metro-config').MetroConfig} */
const config = getDefaultConfig(__dirname);
config.resolver.resolveRequest = (context, realModuleName, platform) => {
if (realModuleName === 'react-native-reanimated-carousel') {
return {
filePath: path.resolve(__dirname, 'node_modules/react-native-reanimated-carousel/lib/module/index.js'),
type: 'sourceFile',
};
}
return context.resolveRequest(context, realModuleName, platform);
};
module.exports = config;
If you're using react-native-reanimated-carousel in an Expo project, you can try the following method:
First, customize the metro configuration by running
npx expo customize metro.config.js
Then modify the code in the
metro.config.js
file to the following:/* eslint-env node */ // Learn more https://docs.expo.io/guides/customizing-metro const { getDefaultConfig } = require('expo/metro-config'); const path = require('path'); /** @type {import('expo/metro-config').MetroConfig} */ const config = getDefaultConfig(__dirname); config.resolver.resolveRequest = (context, realModuleName, platform) => { if (realModuleName === 'react-native-reanimated-carousel') { return { filePath: path.resolve(__dirname, 'node_modules/react-native-reanimated-carousel/lib/module/index.js'), type: 'sourceFile', }; } return context.resolveRequest(context, realModuleName, platform); }; module.exports = config;
Thanks @ystrdy !
I can confirm that doing this fixes the problem.
I was previously using @resticker 's solution. With @ystrdy 's solution I was able to remove the babel plugin and its working fine.
This solution should be added to the docs IMO, specially considering Expo is being recommended by default by RN now.
same here.
Thank you @ystrdy ! Your solution worked for me!
expo: ~51.0.39 => 51.0.39
react-native: 0.74.5 => 0.74.5
react-native-web: ~0.19.10 => 0.19.12
Just to organise the multiple issues going on here:
upgrading to react-native-gesture-handler@2.18.1
In my case, this fixed the following warning:
WARN Require cycle: node_modules/react-native-gesture-handler/lib/commonjs/RNGestureHandlerModule.web.js -> node_modules/react-native-gesture-handler/lib/commonjs/web/Gestures.js -> node_modules/react-native-gesture-handler/lib/commonjs/web/handlers/PanGestureHandler.js -> node_modules/react-native-gesture-handler/lib/commonjs/web/handlers/GestureHandler.js -> node_modules/react-native-gesture-handler/lib/commonjs/handlers/gestureHandlerCommon.js -> node_modules/react-native-gesture-handler/lib/commonjs/RNGestureHandlerModule.web.js
If you're using react-native-reanimated-carousel in an Expo project, you can try the following method:
First, customize the metro configuration by running
npx expo customize metro.config.js
Then modify the code in the
metro.config.js
file to the following:/* eslint-env node */ // Learn more https://docs.expo.io/guides/customizing-metro const { getDefaultConfig } = require('expo/metro-config'); const path = require('path'); /** @type {import('expo/metro-config').MetroConfig} */ const config = getDefaultConfig(__dirname); config.resolver.resolveRequest = (context, realModuleName, platform) => { if (realModuleName === 'react-native-reanimated-carousel') { return { filePath: path.resolve(__dirname, 'node_modules/react-native-reanimated-carousel/lib/module/index.js'), type: 'sourceFile', }; } return context.resolveRequest(context, realModuleName, platform); }; module.exports = config;
In my case, this fixed the following static rendering error:
Cannot access 'computedOffsetXValueWithAutoFillData' before initialization
Are us metro users stuck with this approach forever? It's a circular dependency issue. Is there a cleaner fix?
This issue recommends jumping onto version 4 (not yet stable release) - although for me not completely necessary.
PS. wen v4 release?!
Describe the bug
When starting up metro after migrating to Expo 51, carousel fails during initialization.
Screenshots
Versions (please complete the following information):
Additional context
Using metro to build web.