cloudflare/worker-template-mysql

Top-level await is not available in the configured target

Opened this issue · 6 comments

Hello,
I am facing following error when trying to publish it to cloudflare workers

✘ [ERROR] Top-level await is not available in the configured target environment ("es2020")

    dist/index.mjs:8:1790:
      8 │ ...)});let c=i.level||Ae,_=new Y(r,c,{handlers:s});T.loggers.set(r,_)}}await Qe(X);var dn=await async function(){return{LogLevels:f,Logger:Y,ha...
        ╵                                                                        ~~~~~

✘ [ERROR] Top-level await is not available in the configured target environment ("es2020")

    dist/index.mjs:8:1809:
      8 │ ...Ae,_=new Y(r,c,{handlers:s});T.loggers.set(r,_)}}await Qe(X);var dn=await async function(){return{LogLevels:f,Logger:Y,handlers:_n,LoggerCon...
        ╵                                                                        ~~~~~


✘ [ERROR] Build failed with 2 errors:

  dist/index.mjs:8:1790: ERROR: Top-level await is not available in the configured target
  environment ("es2020")
  dist/index.mjs:8:1809: ERROR: Top-level await is not available in the configured target
  environment ("es2020")

The problem seems to be arising from here:

await setup(DEFAULT_CONFIG);
const mod = await async function () {
    return {
        LogLevels: LogLevels,
        Logger: Logger,
        handlers: handlers1,
        LoggerConfig: LoggerConfig,
        getLogger: getLogger,
        debug: debug,
        info: info,
        warning: warning,
        error: error,
        critical: critical,
        setup: setup
    };
}();

How do I enable Top-level await or how to make it work @nilslice ?

Same issue, did you find a solution?

Same issue, did you find a solution?

Nah man! Hope the author at-least replies @saasryan

change the code likes below, it works for me

let mod
let logger
(async () => {
    try {
        await setup(DEFAULT_CONFIG);
        mod = await async function() {
            return {
                LogLevels: LogLevels,
                Logger: Logger,
                handlers: handlers1,
                LoggerConfig: LoggerConfig,
                getLogger: getLogger,
                debug: debug,
                info: info,
                warning: warning,
                error: error,
                critical: critical,
                setup: setup
            };
        }();
      logger = mod.getLogger();
    } catch (err) {
      console.error(err);
    }
})();