0

I'm writing an ESmodule and have the following code:

const object = {
    key1: 'test',
    key2: 'test2',
}

export {
   ...object
}

It seems you can't export a destructured object?

Is there a workaround that would look clean?

Justin
  • 623
  • 1
  • 10
  • 24
  • 1
    The answer is no, es6 modules are static as allowing this would also allow dynamic exports which is not great as became apparent with CJS modules – Asplund Apr 27 '22 at 19:24
  • You can't directly export "computed" data structures from an ESM module. ESM exports must be statically known (without running the code). In this specific export, you could just do `export object` since there's nothing else in what you're trying to export other than what's in the object you already have. – jfriend00 Apr 27 '22 at 20:49
  • `export object` doesn't work, but I'm able to do `export default object` – Justin Apr 28 '22 at 17:02

0 Answers0