question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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?

Issue Analytics

  • State:open
  • Created 9 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kitsonkcommented, Nov 30, 2018

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

New es6 syntax for importing commonjs / amd modules i.e. ...
A module that uses export = to export another module (be that an internal or external module) can be imported using the new...
Read more >
Writing Modular JavaScript With AMD, CommonJS & ES ...
Understanding AMD: require(). // Consider 'foo' and 'bar' are two external modules; // In this example, the 'exports' from the two modules loaded...
Read more >
AMD is better for the web than CommonJS modules | Blog
AMD is better for the web than CommonJS modules ... exports.foo = foo;. The beauty of CommonJS modules is how simple they are,...
Read more >
Module Methods
If dependencies are not provided, factoryMethod is called with require , exports and module (for compatibility!). If this function returns a value, this...
Read more >
JavaScript modules - MDN Web Docs
This guide gives you all you need to get started with JavaScript module syntax. A background on modules. JavaScript programs started off pretty ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found