Problem with redux-toolkit (createAsyncThunk) in react native expo app

302 Views Asked by At

My problem is on redux-toolkit on a react-native application with Expo. To put you in the context I am quite a beginner.

Here is my code :

export const fetchStationsInformations = createAsyncThunk(
  "stations/fetchStationsInformations",
  async () => {
    console.log(process.env.NODE_ENV);
    if (process.env.NODE_ENV === "test") {
      return require("@data/stationsInformations.json");
    }
    const response = await api.get("/stationsInformations");
    return response.data;
  }
);

export const fetchStationsStatus = createAsyncThunk(
  "stations/fetchStationsStatus",
  async () => {
    console.log(process.env.NODE_ENV);
    if (process.env.NODE_ENV === "test") {
      return require("@data/stationsStatus.json");
    }
    const response = await api.get("/stationsStatus");
    return response.data;
  }
);

I would like to understand why, when in the above code when I let I have in my file the functions fetchStationsInformations and fetchStationsInformations I get this error :

error

error

ERROR  [Error: Exception in HostFunction: Compiling JS failed: 2:20:invalid expression Buffer size 613 starts with: 5f5f642866756e6374696f6e28676c6f and has protection mode(s): rw-p]

While the method fetchStationsStatus is not used and fetchStationsInformations used. I try to clear cash with "expo start --clear".

But if I delete the fetchStationsInformation method then it works. I have looked at a lot of documentation and StackOverflow but I can't find a solution.

1

There are 1 best solutions below

0
Paulin.f On

The problem was quite special and rather silly! The import file in fetchStationStatus was empty. I knew it was empty, but I did not know that an empty file could cause a crash.