'Named export and default export in the same file

I am trying to put default and named export in same file. Example:

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



Solution 1:[1]

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}

Solution 2:[2]

If you're just creating an index file you can just re-export the default and the named seperately

export { default } from "./your-file";
export * from "./your-file";

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 sidonaldson