Relative Content

Tag Archive for javascriptes6-modules

Supporting both AMD and ES6 modules

Is there a syntax that allows a library to be compatible with being loaded as either an AMD or ES6 module? Right now I have two different *.js files for each module. One with a define(()=>{ ... for AMD and one with a export { ModuleName} for ES6. The export keyword doesn’t seem to be valid for anywhere other than root scope, so trying to place it in any kind of conditional does not work. If loaded as an AMD module, it generates the error SyntaxError: Unexpected token 'export'.