Last Updated: February 25, 2016
· jaysoo

[RequireJS] Using exports in CoffeeScript modules

If you use RequireJS with exports in CoffeeScript, make sure the last line of your file is not:

exports = MyModule


exports.Foo = Foo

Since CoffeeScript has implicit returns, that will get compiled down to:

return exports = MyModule


return exports.Foo = Foo

This will sometimes result in situations where requiring that module will give you an empty object {}.

To fix this you can either:

1) Just use explicit return and avoid using exports.

2) Put and empty return at the end of your module.