ES6 support with app builder | Community
Skip to main content
February 27, 2024
Question

ES6 support with app builder

  • February 27, 2024
  • 1 reply
  • 775 views

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.
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

sarav_prakash
Community Advisor
Community Advisor
September 3, 2024

@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.