0

I have the files main.js, a.js and b.js:

main.js

import { foo } from './a'

console.log(foo)

a.js

import objWithFoo from './b'

const bar = 24

export default { ...objWithFoo, bar }

b.js

const foo = 42

export default { foo }

When I ran main.js using node -r esm main.js it gave me this error:

SyntaxError: The requested module 'file:///app/a.js' does not provide an export named 'foo'

Question:

Why is it loosing the named export?

Vitor Falcão
  • 1,007
  • 1
  • 7
  • 18

1 Answers1

0

You aren't using named exports - you are default exporting an object with properties.

import stuff from './a';

const { foo } = stuff;
...

If you wanted to use named exports:

import objWithFoo from './b'

const foo = { objWithFoo }
export { foo } // <- named export

const bar = 24
export default { bar } // <- object with properties
Adam Jenkins
  • 51,445
  • 11
  • 72
  • 100