UG_ UG_ - 1 month ago 8
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,
post,
put,
get,
};

// 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 ?

UG_ UG_
Answer

Found the solution here : http://exploringjs.com/es6/ch_modules.html

Basically, I had to do

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