Skip to content

Named exports + destructuring for env preset doesn't work. #6234

Closed

Description

@Kerrick

This is a bug report.

Input Code

const exports = {};
exports.Foo = 'hello';

export const { Foo } = exports;

export default exports;

Babel REPL link

Babel Configuration (.babelrc, package.json, cli command)

The babel configuration as shown in the REPL above is to compile with the Env preset, set to last 1 chrome version.

Expected Behavior

With the code above, import { Foo } from 'that-file' should give you access to the string 'hello'.

'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
const _exports = {};
_exports.Foo = 'hello';

const { Foo } = _exports;
exports.Foo = Foo;
exports.default = _exports;

In this imaginary case, you can see that Foo would be attached to exports.

Current Behavior

With the code above, import { Foo } from 'that-file' means that Foo is undefined.

'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
const _exports = {};
_exports.Foo = 'hello';

const { Foo } = _exports;

exports.default = _exports;

In this case, you can see that Foo is not attached to exports.

Activity

  1. babel-bot commented on Sep 12, 2017

    @babel-bot
    Collaborator

    Hey @Kerrick! We really appreciate you taking the time to report an issue. The collaborators
    on this project attempt to help as many people as possible, but we're a limited number of volunteers,
    so it's possible this won't be addressed swiftly.

    If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
    community that typically always has someone willing to help. You can sign-up here
    for an invite.

  2. loganfsmyth commented on Sep 12, 2017

    @loganfsmyth
    Member

    This will be fixed in 7.x with #6234

  3. added
    outdated
    on May 4, 2018
  4. locked as resolved and limited conversation to collaborators on May 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    outdated

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions