sveltekit-adapter-aws icon indicating copy to clipboard operation
sveltekit-adapter-aws copied to clipboard

Svelte-5, top level await & ESM output

Open k-dahl opened this issue 10 months ago • 2 comments

I'm unable to deploy svelte-5 with this adapter and the new svelte.js/ts files with top-level await because the lambda here gets compiled as CJS, which does not support top level await.

I tried passing in esbuild: { format: 'esm' } via the adapter config, and that gets me a little further with a successful deploy - but the resulting lambda function then fails on every request with:

{
    "errorType": "Runtime.UserCodeSyntaxError",
    "errorMessage": "SyntaxError: Cannot use import statement outside a module",
    "stack": [
        "Runtime.UserCodeSyntaxError: SyntaxError: Cannot use import statement outside a module",
        "    at _loadUserApp (file:///var/runtime/index.mjs:1084:17)",
        "    at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)",
        "    at async start (file:///var/runtime/index.mjs:1282:23)",
        "    at async file:///var/runtime/index.mjs:1288:1"
    ]
}

my package.json does have "type": "module" but I suspect the issue is specific to the esbuild options.

Any insights you could provide would be greatly appreciated!

k-dahl avatar Jan 15 '25 23:01 k-dahl