Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to re-export another module's default export? [duplicate]

I want to export some module like below way but always failed..

foo.js

const foo = {
  a: 'b'
};
export default foo;

index.js

export foo from './foo';  // encounter error here
export * from './foo';    // it works..

I don't know why can't I use the first method to export module from foo.js, in my opinion, I can export anything like func, class, variables etc..

like image 319
E_Jovi Avatar asked Dec 11 '22 13:12

E_Jovi


1 Answers

To export a default export of one module as a named export of another you must do:

// index.js
export { default as foo } from './foo';

You can now import foo as a named export elsewhere:

// another.js
import { foo } from './index'
like image 123
sdgluck Avatar answered Mar 05 '23 20:03

sdgluck