Skip to content

External modules with AMD always requires "exports" even when it is not used #669

Open

Description

@xirzec

Here's a small external module that explicitly exports a module:

module Foo {
    export var foo = 42;
}
export = Foo;

The code generated for this is:

define(["require", "exports"], function(require, exports) {
    var Foo;
    (function (Foo) {
        Foo.foo = 42;
    })(Foo || (Foo = {}));

    return Foo;
});

This feels like bad AMD since you are requiring the "exports" magic dependency, but then not using it and instead returning Foo directly.

It's annoying for minimal AMD loaders since they can't assume the object return of your module is your "exports" object and have to guess that you really meant to return something that overrode the "exports" object you asked for.

Furthermore, why bother declaring a dependency on 'require' when it's not used?

Activity

  1. RyanCavanaugh commented on Sep 15, 2014

    @RyanCavanaugh
    Member

    Seems like a reasonable proposal

  2. added this to the milestone on Apr 27, 2015
  3. RyanCavanaugh commented on Apr 27, 2015

    @RyanCavanaugh
    Member

    Approved

  4. RoyTinker commented on Jul 4, 2017

    @RoyTinker
  5. amandaol commented on Nov 30, 2018

    @amandaol

    Has this been implemented yet? I need it...

  6. kitsonk commented on Nov 30, 2018

    @kitsonk
    Contributor

    AmandaO (@amandaol) the tags on the issue indicate that it is up to the community to implement. Coupled with the issue still being open means that the it hasn't been implemented.

  7. RoyTinker commented on Dec 1, 2018

    @RoyTinker

    For what it's worth, we now use amdextract in our build pipeline after tsc to remove the unnecessary require and exports from emitted JS.

    https://github.com/mehdishojaei/amdextract

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

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions