Ability to apply destructing in server.js

I am glad that starting from fdk 7 support es6+ features of javascript.

However, fdk still throws the following error during testing onConversationCreate event

❯ fdk run
The local server could not be started due to the following issue(s):
[ERROR] Exception occured while validation: Error while parsing file containing serverless functions. Please use the exports section as recommended in the Serverless Apps section of the SDK documentation.

Although I am on the right & latest version

❯ fdk version
Installed: 7.3.0
Already Up to Date..!

I concluded destructuring is not supported when I saw the following debug logs

(validate.js) running validator event
(event-util.js) error while parsing server file "Line 68: Unexpected token ..."
(event.js) Error: Error while parsing file containing serverless functions. Please use the exports section as recommended in the Serverless Apps section of the SDK documentation.
    at Object.getEventsList (/usr/local/lib/node_modules/fdk/lib/utils/event-util.js:112:11)

Where on Line 68 ... is not supported. My code looks similar to follows

      let { data: requesterDetails } = await axios.request(OptsToGetServiceReqDetails);
      let OptsToGetCustomFieldDetails = {
        url: `/tickets/${ticket_id}/requested_items`,
        ...OptsToGetServiceReqDetails // `...` destructing here
      };

I wonder if there’s any eslint disable rule I could add if this restriction is limited to CLI experience alone.

Not going to be much help here, but are you having this issue on serverless apps? I’m also having issues getting it work but only on serverless apps.

What’s your Node.js version?

If the line ...OptsToGetServiceReqDetails is line 68, then your issue is with the spread operator, and not with destructuring objects.

However, I tested and both object merge and object spread work on fdk v7.0.0+, last tested with v7.3.0 on Node.js v12.22. I have attached a sample app that I used to test this. Run that and see if you can reproduce the same errors.

async-await.zip (4.7 KB)

If you can produce the same errors using this ^ attachment, then there would be something up with FDK. Else, we’ll have to investigate the rest of your code to see what’s going on there.

The other error is likely from using import/export (ECMAScript modules) syntax. ES modules syntax is not supported for apps yet. You will have to use CommonJS exports (require and exports).


Fun fact: Unicode can be visually confusing sometimes. These two are different things: ... (3 dots), (horizontal ellipsis).

1 Like