Module Export Syntax

When exporting functions in the following files, we recommend you use the standard export syntax contained in the documentation's code examples:

You can also use other export formats that are part of the ES6 (ES2015) module export syntax. However, the following export formats are not supported in events.js, data.js, routers.js, or SPI code files:

  • Re-exporting a function: Directly re-exporting a function imported from an npm or Velo package. For example, this doesn't work:

    Copy
    1
    import { myFunction } from 'myPackage';
    2
    3
    export const wixMediaManager_onFileUploaded = myFunction;

    The following alternative syntax is supported:

    Copy
    1
    import { myFunction } from 'myPackage';
    2
    3
    export const wixMediaManager_onFileUploaded = (paramA, paramB) => myFunction(paramA, paramB);
  • Dynamic exports: Exports including a dynamic operation or expression that requires execution to resolve. For example, this doesn't work:

    Copy
    1
    import myPackage from 'my-package';
    2
    3
    export const myRouter_Router = myPackage.router((paramA, paramB) => {
    4
    // ...
    5
    });

    The following alternative syntax is supported:

    Copy
    1
    import myPackage from 'my-package';
    2
    3
    const functionForExport = myPackage.router((paramA, paramB) => {
    4
    // ...
    5
    })
    6
    7
    export const myRouter_Router = (paramA, paramB) => functionForExport(paramA, ParamB);
  • Exports wrapped in objects: Exports where functions are defined as properties of an object. For example, this doesn't work:

    Copy
    1
    const dataHooks = {
    2
    beforeInsert: (paramA, paramB) => {
    3
    // ...
    4
    }
    5
    };
    6
    7
    export const MyCollection_beforeInsert = dataHooks.beforeInsert;

    The following alternative syntax is supported:

    Copy
    1
    const dataHooks = {
    2
    beforeInsert: (paramA, paramB) => {
    3
    // ...
    4
    }
    5
    };
    6
    7
    export const MyCollection_beforeInsert = (paramA, paramB) => dataHooks.beforeInsert(paramA, paramB);
  • CommonJS exports: Exports in the CommonJS (CJS) format that preceded ES6 (ES2015). For example, this doesn't work:

    Copy
    1
    module.exports = {
    2
    MyCollection_beforeInsert: () => {}
    3
    };

Functions exported using a syntax that isn't supported aren't called by the triggering event.

Was this helpful?
Yes
No