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 ?
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.
Exports without a default tag are Named exports. Exports with the default tag are Default exports. Using one over the other can have effects on your code readability, file structure, and component organization. Named and Default exports are not React-centric ideas.
The only natural restriction to multiple exports is the default export. In each file, there can be only one default export function.
What are Named Exports? Named exports allow us to share multiple objects, functions or variables from a single file and were introduced with the release of ES2015. Named exports are imported with curly braces in various files and must be imported using the name of the object, function or variable that was exported.
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}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With