pierre
pierre

Reputation: 11

A module cannot have multiple default exports.ts(2528)

I'm trying to implement switch case for my products in Redux. I'm importing the cases from a file named productConstants using multiple export defaults. Problem is, the moment I write multiple lines, my screen turns red with this error 'A module cannot have multiple default exports.ts(2528)'

productReducers.js file

    ALL_PRODUCTS_REQUEST, 
    ALL_PRODUCTS_SUCCESS, 
    ALL_PRODUCTS_FAIL} from '../constants/productConstants'

export const productsReducer = (state ={ products: [] }, action => {
    switch(action.type) {


        default:
            return state;
    }
})

my productConstants.js file
```export default ALL_PRODUCTS_REQUEST = 'ALL_PRODUCT_REQUEST'

export default ALL_PRODUCTS_SUCCESS = 'ALL_PRODUCT_SUCCESS'

export default ALL_PRODUCTS_FAIL = 'ALL_PRODUCT_FAIL'

export default CLEAR_ERRORS = 'CLEAR_ERRORS'

here is my store.js file
```//import { configureStore } from '@reduxjs/toolkit'
import {  createStore, combineReducers, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import { composeWithDevTools } from 'redux-devtools-extension'

const reducer = combineReducers({

})

let initialState = {}

const middleware = [thunk];
const store = createStore( reducer, initialState, composeWithDevTools(applyMiddleware(...middleware))) 

export default store;

and finally, my index.js file
```import React from "react";
import ReactDOM from "react-dom";
import App from "./App";

import { Provider } from 'react-redux'

import store from './store'

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

How do I do away with this error? A module cannot have multiple default exports.ts(2528)
productConstants.js(1, 1): The first export default is here.

Upvotes: 1

Views: 2201

Answers (1)

Milenko
Milenko

Reputation: 539

A module can have only one default export per module, meaning that in one JS file only one variable (or function) can be exported with the default keyword.

You can convert them all to named export:

export const ALL_PRODUCTS_FAIL = 'ALL_PRODUCT_FAIL'

Upvotes: 1

Related Questions