Attempted import error: './movieReducer' does not contain a default export (imported as 'movieReducer')

Shoto Amb

I'm starting learn React + Redux , I'm doing a simple application for add or remove a movie in a basket.

But I have a problem on a reducer . I try a lot of things without result...

Thanks in advance :)

Here is my code :

The reducer :

import '../actions/actionsTypes';

import { movies } from '../components/movie/data.json';

let initialState = []

movies.map((movie) => {
initialState.push({
id : movie.id,
title: movie.title,
year: year.title,
isAdd: false,
isRemove: false
})
return movie
})

const establishment = (state = {}, action) => {

    switch (action.type) {

        case ADD :

          if (state.id !== action.data.id)
               return state


        return (
          ...state,
          isAdd : !state.isAdd

        )

        case REMOVE :
          if (state.id !== action.data.id)
            return state

            return (
              ...state,
              isRemove : !state.isRemove

            )

        default:
          return state
    }

}

const establishmentsReducer = (state = initialState, action) => {

    switch (action.type) {

        case ADD :
          return state.map(movieState =>
            movie(movieState, action)
          )


        case REMOVE :
          return state.map(movieState =>
              movie(movieState, action)
          )

        default:
          return state

    }

}

export default movieReducer;

The connection of the reducer ( I know it's not useless but in the furtur will have to combine reducer ) :

import { combineReducers } from 'redux';

import movieReducer from './movieReducer';


const allReducers = combineReducers({
movie : movieReducer
})

export default allReducers;

index.js :

import React from 'react';
import ReactDOM from 'react-dom';

import { createStore } from 'redux';
import { Provider } from 'react-redux';

import allReducers from './reducers';

import './index.css';
import App from './components/App';
import * as serviceWorker from './serviceWorker';


const store = createStore(allReducers);

ReactDOM.render(
  <Provider store={ store }>
  <App/>
  </Provider>,
  document.getElementById('root')

)
Alexander Staroselsky

In your reducer, change:

export default movieReducer;

To:

export default establishmentsReducer;

This is because you need to export an actually defined function or variable, in this case establishmentsReducer. The code you shared in the reducer file does not have any functions/variables/expressions defined/named as movieReducer.

Another option would be to just change const establishmentsReducer = (state = initialState, action) => { to const movieReducer = (state = initialState, action) => {.

Hopefully that helps!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Attempted import error: does not contain a default export

why I am receiving this error Attempted import error: 'history' does not contain a default export (imported as 'createBrowserHistory')

Attempted import error: 'react-table' does not contain a default export (imported as 'ReactTable')

React-Redux: Attempted import error: './components/Score' does not contain a default export (imported as 'Score')

Attempted import error: 'uuid' does not contain a default export (imported as 'uuid') In React

React JS Attempted import error: './Pathfinder/Pathfinder' does not contain a default export (imported as 'Pathfinder')

Spine and Reactjs issues error @esotericsoftware/spine-player' does not contain a default export (imported as 'spine')

does not contain a default export even after being correctly imported in React

Attempted import error: 'app' is not exported from 'firebase/app' (imported as 'firebase')

Attempted import error: 'OBJLoader' is not exported from 'three' (imported as 'THREE')

When I try to export action with redux I get an error that says "does not contain a default export"

module.exports does not contain a default export

Component index does not contain a default export

Attempted import error: 'default' is not exported from '../assertThisInitialized/_index.mjs'

Attempted import error: 'BrowseRouter' is not exported from 'react-router-dom' (imported as 'Router')

Upgrade to Firebase JS 8.0.0: Attempted import error: 'app' is not exported from 'firebase/app' (imported as 'firebase')

React import error when using export default

Should not import the named export 'todos' (imported as 'todos') from default-exporting module (only default export is available soon)

does not contain an export named

No matching export for import "default"

Can't import d3-queue in React.js? Attempted import error: 'queue' is not exported from 'd3' (imported as 'd3')

Receiving "Attempted import error:" in react app

Build failed to compile - Attempted import error

Attempted import error: 'Typography' is not exported from 'antd'

Attempted import error: 'SomeObject' is not exported from file

Attempted import error: 'Model' is not exported from '../module'

Attempted import error : 'createLocation' is not exported from 'history'

Attempted import error: 'Icon' is not exported from 'antd'

Attempted import error: '_' is not exported from 'underscore'