UG_ UG_ - 2 years ago 154
Javascript Question

Named export and default export as the same time

I am trying to put default and named export in same file.
ex :
// file name : utils/fetch

export default fetchUtil;

module.exports = {
fetch : fetchUtil,

// import code
import fetch from 'utils/fetch';

My code builds fine with webpack, however in browser I get errors :

fetchInit.js:27 Uncaught TypeError: (0 , _fetch2.default) is not a function

Am I missing something or is this not the way to do default & named import in the same file ?

Answer Source

Found the solution here :

Basically, I had to do

export default fetchUtil export {fetchUtil as fetch, post, put, get}

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download