Expand my Community achievements bar.

ES6 support with app builder

Avatar

Level 2

Hi,

Using these instructions ( https://developer.adobe.com/app-builder/docs/getting_started/first_app/ ) , we created hello world app and trying use ES6 library ( https://www.npmjs.com/package/critical ) but import is failing 

 

tried by creating .mjs file as ( index.mjs ) 

import {generate} from 'critical'

export default function (params) {
return {
statusCode: 200,
headers: {
'Content-Type': 'application/json'
},
body: {
LOG_LEVEL: params.LOG_LEVEL,
message: 'this is a test message'
}
}
}

Really blocked with next steps.
Thanks in advance.
Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Reply

Avatar

Level 6

@venkiiitk , you are missing syntax. Your index.mjs must look like this 

 

import {generate} from 'critical'

function main(params) {
  const logger = Core.Logger("main", { level: params.LOG_LEVEL || "info" });
  logger.info("Hello world runtime action");
  return {
    statusCode: 200,
    headers: {
      'Content-Type': 'application/json'
    },
    body: {
      LOG_LEVEL: params.LOG_LEVEL,
      message: 'this is a test message'
    }
  }
}

const _main = main;
export { _main as main };

 

Key is, default export must look like 

`export { _main as main };`
 
I dono why. But boilerplate expects in exact syntax. From index.mjs, we can create other *.mjs and write esm code. works fine.