Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: 0, _$$_REQUIRE(_dependencyMap[15], "redux").isAction is not a function (it is undefined) #1473

Open
haveamission opened this issue Jul 8, 2024 · 1 comment

Comments

@haveamission
Copy link

haveamission commented Jul 8, 2024

I am getting this error on iOS only so far.

Seems to only happen when Redux Persist is enabled.

Relevant libraries:

    "@reduxjs/toolkit": "^2.2.6",
    "react": "18.2.0",
    "react-native": "0.72.10",
    "redux": "^4.2.1",
    "redux-api-middleware": "^3.2.0",
    "redux-mock-store": "^1.5.4",
    "redux-persist": "^6.0.0",
    "redux-persist-expire": "^1.1.0",
    "redux-persist-transform-immutable": "^5.0.0",
    "redux-saga": "^1.3.0",

And the store:

import { configureStore } from '@reduxjs/toolkit';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { historyexport } from 'reducers/history';
import {
  persistStore,
  persistReducer,
  FLUSH,
  REHYDRATE,
  PAUSE,
  PERSIST,
  PURGE,
  REGISTER,
} from 'redux-persist';
import expireReducer from 'redux-persist-expire';
import { API } from 'utils/RTKAPI';
import { GraphQLAPI } from 'utils/RTKGraphQL';
import createSagaMiddleware from 'redux-saga';
import rootReducer from 'reducers/rootReducer';
import { formatDateYMD } from 'utils/misc';
import { settingsSave } from 'reducers/slices/settings';
import { mapToCamelCase } from 'app/resources/data/settings';
import settingsSaga from 'reducers/sagas/settingsSaga';

export const history = historyexport;

const sagaMiddleware = createSagaMiddleware();

const persistConfig = {
  key: 'root',
  storage: AsyncStorage,
  version: 1,
  blacklist: [
    API.reducerPath,
    GraphQLAPI.reducerPath,
    'router',
    'sidebar',
    'currentchar',
  ],
  transforms: [
    expireReducer('date', {
      expireSeconds: 86400,
      expiredState: {
        end_date: formatDateYMD(Date.now()),
        start_date: '2021-07-04',
      },
      autoExpire: true,
    }),
  ],
};

const loggerMiddleware = (store) => (next) => (action) => {
  //console.log("Action type:", action.type);
  //alert("Action type:" + action.type);
  //console.log(action);
  //console.log("Action payload:", action.payload);
  //console.log("State before:", store.getState());
  //alert(JSON.stringify(store.getState()))

  //console.log("State after:", store.getState());
  return next(action);
};

function promiseMiddleware({ dispatch }) {
  function isPromise(val) {
    return val && typeof val.then === 'function';
  }

  return (next) => (action) => {
    return isPromise(action.payload)
      ? action.payload.then(
          (result) => dispatch({ ...action, payload: result }),
          (error) => dispatch({ ...action, payload: error, error: true })
        )
      : next(action);
  };
}

const settingsSyncMiddleware = (store) => (next) => async (action) => {
  if (action.type === settingsSave.type) {
    const state = store.getState();
    const isAuthenticated = !!state.profile;
    if (isAuthenticated) {
      try {
        const mappedSettings = mapToCamelCase(action.payload);
        const response = await store.dispatch(
          GraphQLAPI.endpoints.createOrUpdateUserSettings.initiate({
            userId: state.profile.id,
            ...mappedSettings,
          })
        );
        if (JSON.stringify(response.data) !== JSON.stringify(state.settings)) {
          store.dispatch({
            type: 'settingsSyncSuccess',
            payload: response.data,
          });
        }
      } catch (error) {
        console.error('Error syncing settings:', error);
        store.dispatch({ type: 'settingsSyncFailure', payload: error });
      }
    }
  }
  return next(action);
};

const persistedReducer = persistReducer(persistConfig, rootReducer(history));

export const makeStore = () => {
  const store = configureStore({
    middleware: (getDefaultMiddleware) =>
      getDefaultMiddleware({
        serializableCheck: {
          ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
        },
      }).concat(
        loggerMiddleware,
        promiseMiddleware,
        sagaMiddleware,
        API.middleware,
        GraphQLAPI.middleware,
        settingsSyncMiddleware
      ),
    reducer: persistedReducer,
  });

  sagaMiddleware.run(settingsSaga);

  return store;
};

export const store = makeStore();

export const persistor = persistStore(store);

@sahad00
Copy link

sahad00 commented Sep 20, 2024

@haveamission did u get any solution ? I am facing a similar issue

Warning: TypeError: 0, _$$_REQUIRE(_dependencyMap[35(...)elper").getSortedMiniAppsScreens is not a function (it is undefined)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants