Export multiple classes in ES6 modules

I’m trying to create a module that exports multiple ES6 classes. Let’s say I have the following directory structure:

my/
└── module/
    ├── Foo.js
    ├── Bar.js
    └── index.js

Foo.js and Bar.js each export a default ES6 class:

// Foo.js
export default class Foo {
  // class definition
}

// Bar.js
export default class Bar {
  // class definition
}

I currently have my index.js set up like this:

import Foo from './Foo';
import Bar from './Bar';

export default {
  Foo,
  Bar,
}

However, I am unable to import. I want to be able to do this, but the classes aren’t found:

import {Foo, Bar} from 'my/module';

What is the correct way to export multiple classes in an ES6 module?

6 Answers
6

Leave a Comment