cloudflare / worker-template-mysql

Reference demo and modified MySQL driver to connect Cloudflare Workers to a relational database.
Apache License 2.0
49 stars 15 forks source link

Top-level await is not available in the configured target #4

Open delivrjs opened 2 years ago

delivrjs commented 2 years ago

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 ?

saasryan commented 2 years ago

Same issue, did you find a solution?

on-future commented 2 years ago

+1

delivrjs commented 2 years ago

Same issue, did you find a solution?

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

SirRodney commented 2 years ago

+1

Hundeklemmen commented 1 year ago

+1

shiyuhang0 commented 1 year ago

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);
    }
})();