dohooo / react-native-reanimated-carousel

šŸŽ  React Native swiper/carousel component, fully implemented using reanimated v2, support to iOS/Android/Web. (Swiper/Carousel)
https://react-native-reanimated-carousel.vercel.app
MIT License
2.58k stars 293 forks source link

[4.0.0-alpha12] Metro error on Expo 51 / Web: Cannot access 'computedOffsetXValueWithAutoFillData' before initialization #634

Open mortenmo opened 2 days ago

mortenmo commented 2 days ago

Describe the bug

When starting up metro after migrating to Expo 51, carousel fails during initialization.

Screenshots

Metro error: Cannot access 'computedOffsetXValueWithAutoFillData' before initialization

   5 | });
   6 | exports.computedFillDataWithAutoFillData = computedFillDataWithAutoFillData;
>  7 | exports.computedOffsetXValueWithAutoFillData = computedOffsetXValueWithAutoFillData;
     |                                                ^
   8 | exports.computedRealIndexWithAutoFillData = computedRealIndexWithAutoFillData;
   9 | exports.convertToSharedIndex = convertToSharedIndex;
  10 |

Call Stack
  factory (node_modules/react-native-reanimated-carousel/lib/commonjs/utils/computed-with-auto-fill-data.js:7:48)
  loadModuleImplementation (node_modules/metro-runtime/src/polyfills/require.js:273:5)
  guardedLoadModule (node_modules/metro-runtime/src/polyfills/require.js:180:12)
  require (node_modules/metro-runtime/src/polyfills/require.js:89:7)
  factory (node_modules/react-native-reanimated-carousel/lib/commonjs/components/ItemRenderer.js:16:33)
  loadModuleImplementation (node_modules/metro-runtime/src/polyfills/require.js:273:5)
  guardedLoadModule (node_modules/metro-runtime/src/polyfills/require.js:180:12)
  require (node_modules/metro-runtime/src/polyfills/require.js:89:7)
  factory (node_modules/react-native-reanimated-carousel/lib/commonjs/components/Carousel.js:16:21)
  loadModuleImplementation (node_modules/metro-runtime/src/polyfills/require.js:273:5)

Versions (please complete the following information):

Additional context

Using metro to build web.

dosubot[bot] commented 2 days 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.