Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attempted import error: does not contain a default export

I'm defining react component to connect with redux . I have the app and list components

App.js

import React, { Component } from 'react';
  //import Login from './components/Login';
 import List from './components/List';
 import './App.css';
  class App extends Component {
 render() {
  return (  <List />); } }
  export default App;

List.js

  import React from 'react';
  import { connect } from 'react-redux';

  const mapStateToProps=  state =>{
     return { articles :state.articles};
      }
   const connectedList = ({ articles }) =>(
        {articles.map(e=>(      //////**1) here I get red under the dot(.) ie., error**
           <li key={e.id}>{e.title}</li>
         ))}
     );
   const List= connect(mapStateToProps)(connectedList);
   export default List;

why do 1) here I get red under the dot(.) ie., error

I have exported List but I'm thrown this error

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

Actually I'm newbie to redux so Please explain lemme know where i'm going wrong?

like image 872
Tested Avatar asked Dec 02 '18 03:12

Tested


People also ask

How do I fix attempted import error?

To solve the "Attempted import error 'X' is not exported from" error, be consistent with your ES6 imports and exports. If a value is exported as a default export, it has to be imported as a default import and if it's exported as a named export, it has to be imported as a named import.

Can't import the named export from default exporting module only default export is available?

Can't import the named Export children from non EcmaScript module only default export is available? Solution: You Just need to Downgrade the Framer motion version to “4.1. 17” in your package. json file and then run npm install Now, Your error must be solved.

Why you shouldn't use default exports?

Default exports make large-scale refactoring impossible since each importing site can name default import differently (including typos). On the contrary, named exports make such refactoring trivial.

Can you export default multiple?

Every module can have two different types of export, named export and default export. You can have multiple named exports per module but only one default export.


1 Answers

Remove curly brace:

const connectedList = ({ articles }) =>(
   articles.map(e=>( // implicit return
      <li key={e.id}>{e.title}</li>
   )
));

Or, using curly brace:

const connectedList = ({ articles }) => { // no parentheses
   return articles.map(e=>( // explicitly use return
      <li key={e.id}>{e.title}</li>
   )
});

Using curly brace in parentheses indicates that you're returning an object. But articles.map... is obviously not an object rather looping through an object.

like image 97
Bhojendra Rauniyar Avatar answered Oct 27 '22 13:10

Bhojendra Rauniyar