PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, November 25, 2022

[FIXED] Why export default doesn't work in this simple code?

 November 25, 2022     export, import, javascript, module, reactjs     No comments   

Issue

Why when I use export default on index.js module it says: export 'appReducers' (imported as 'appReducers') was not found in './reducers/index' (possible exports: default), but when I change it to module.exports the error go away, why is that?

At redux.js

import { appReducers } from './reducers/index'

const Store = () => {
  console.log(appReducers);
}

export default Store

in index.js

const appReducers = "hello world";
export default appReducers

in app.js

import React, { useState, useEffect, useMemo } from 'react';
import Store from './redux'

function App() {
  Store();
  return (
    <div>

    </div>
  );
}

export default App;

Solution

The problem is in redux.js. Instead of

import { appReducers } from './reducers/index'

You need

import appReducers from './reducers/index'

What you were doing before was a named import, not a default import.



Answered By - adsy
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing