Home > front end >  export 'actionTypes' (imported as 'actionTypes') was not found in './pages.
export 'actionTypes' (imported as 'actionTypes') was not found in './pages.

Time:02-27

I am building a React app that uses Redux-Thunks. I am receiving an error message and cannot figure out how to resolve it. I am new to using Redux-Thunks and have been using this tutorial to set up . I checked all my dependencies and files to ensure I did as instructed but still I have been unable to resolve this bug.

The error message is:

pages.thunks.js

export 'default' (imported as 'actions') was not found in './pages.actions' (possible exports: pagesLoadError, pagesLoadStart, pagesLoadSuccess)

Although page.thunks.js is receiving error messages I believe the issue is coming from pages.actionTypes.js and pages.initialState.js

pages.actionTypes.js

export default  {    
   PAGES_LOAD_START: "PAGES_LOAD_START",
    PAGES_LOAD_SUCCESS: "PAGES_LOAD_SUCCESS",
    PAGES_LOAD_ERROR: "PAGES_LOAD_ERROR",
}

pages.initialState.js

export default {
    isLoading: false,
    pages: null,
    errorMessage: null,
};

pages.thunks.js

import PagesServices from '../../../services/pages.services.js';
import actions from './pages.actions';

export const loadPagesAsync = () => (dispatch) => {
    dispatch(actions.pagesLoadStart())

    PagesServices.getAllPages()
        .then(response => dispatch(actions.pagesLoadSuccess(response.data)))
        .catch(error => dispatch(actions.pagesLoadError(error.message)))
}

pages.actions.js

import actionTypes from './pages.actionTypes'

export const pagesLoadStart = () => ({
    type: actionTypes.PAGES_LOAD_START,
})

export const pagesLoadSuccess = pages => ({
    type: actionTypes.PAGES_LOAD_SUCCESS,
    payload: pages
})

export const pagesLoadError = errorMessage => ({
    type: actionTypes.PAGES_LOAD_ERROR,
    payload: errorMessage
})

CodePudding user response:

You are exporting pagesLoadStart, pagesLoadSuccess and pagesLoadError from pages.actions.js yet you are trying to import actions from it. That isn't going to work - there is no actions object exported by pages.actions.js

To fix, change the second line of pages.thunks.js to:

import * as actions from './pages.actions';

The rest of your code should work fine, though you may only want to import specific functions.

  • Related