Skip to content

Question regarding mixing default and named exports #1961

@transitive-bullshit

Description

@transitive-bullshit

I have a react module boilerplate which makes use of rollup, and some users are requesting the ability to export multiple components.

I'm bundling to cjs and es formats (rollup.config.js), so including both named and default exports from my bundle should be fine as I understand it, but rollup prints a warning about the use of mixed default and named exports.

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

// export Foo and Bar as named exports
export { Foo, Bar }

// alternative, more concise syntax for named exports
// export { default as Foo } from './Foo'

// you could also export a default object containing your module's interface
// note that if you export both named and default exports, rollup will complain.
// if you know how to prevent this warning, please let me know :)
// export default { Foo, Bar }

For more context, see this thread.

In particular, I can see why this would be a problem for umd bundles (source), but I'm not sure why rollup is complaining for es and cjs bundles.

Any idea how we could resolve this issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions