Receiving "Attempted import error:" in react app

ReactjsRedux

Reactjs Problem Overview


I am receiving the following error when trying to run my React app:

> ./src/components/App/App.js
> Attempted import error: 'combineReducers'
> is not exported from '../../store/reducers/'.

Here's how I'm exporting combineReducers:

import { combineReducers } from 'redux';
import userReducers from './userReducers';
import articleReducers from './articleReducers';

export default combineReducers({
	userReducers,
	articleReducers
});

and here's how I'm importing it in App.js:

import { combineReducers } from '../../store/reducers';

What's incorrect in how I'm exporting combineReducers?

Reactjs Solutions


Solution 1 - Reactjs

import { combineReducers } from '../../store/reducers';

should be

import combineReducers from '../../store/reducers';

since it's a default export, and not a named export.

There's a good breakdown of the differences between the two here.

Solution 2 - Reactjs

i had the same issue, but I just typed export on top and erased the default one on the bottom. Scroll down and check the comments.

import React, { Component } from "react";

export class Counter extends Component { // type this  
export default Counter; // this is eliminated  

Solution 3 - Reactjs

I guess I am coming late, but this info might be useful to anyone I found out something, which might be simple but important. if you use export on a function directly i.e

export const addPost = (id) =>{
  ...
 }

Note while importing you need to wrap it in curly braces i.e. import {addPost} from '../URL';

But when using export default i.e

const addPost = (id) =>{
  ...
 }

export default addPost,

Then you can import without curly braces i.e. import addPost from '../url';

export default addPost

I hope this helps anyone who got confused as me. 

Solution 4 - Reactjs

This is another option:

export default function Counter() {
    
}

  

Solution 5 - Reactjs

Maybe i'm late too but i had a similar problem with folders inside of component folder. i changed the folder's name with Capital letter. it worked for me.

Solution 6 - Reactjs

If changing the import doesn't help maybe you just need to run yarn install or npm install (or whatever you're using) and restart your server. Worked for me.

Solution 7 - Reactjs

Be sure to Capitalize the name of the constant variable you're exporting inside the component. When you Import the component elsewhere you should also check that its first letter is capitalized since this is one of the ways React uses to identify its components.

inside component:

import React from 'react';

export const Component =  (props) => (...)

And then, when importing:

import {Component} from '../location/file'

Solution 8 - Reactjs

Take into consideration that if you are using a named export you don't need curly brackets:

export const Component 

->

 import {ComponentName}

Only the default exported component be imported with curly brackets:

export default 

->

import ComponentName

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAndrewView Question on Stackoverflow
Solution 1 - ReactjsColin RicardoView Answer on Stackoverflow
Solution 2 - Reactjsjmisael56yahoocomView Answer on Stackoverflow
Solution 3 - ReactjsMicheal N.DView Answer on Stackoverflow
Solution 4 - ReactjsLloyd Janse van RensburgView Answer on Stackoverflow
Solution 5 - ReactjsCarlos Espinoza GarciaView Answer on Stackoverflow
Solution 6 - ReactjsShashiiView Answer on Stackoverflow
Solution 7 - ReactjsEdward Anthony Escudero BowieView Answer on Stackoverflow
Solution 8 - ReactjsSterling DiazView Answer on Stackoverflow