-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Netlify and Vercel lambda functions expect CJS, not ESM #400
Comments
I contacted Vercel support and they said that they do support ESM functions, which Next.js supposedly does out of the box. Will follow up when I get more details. |
@leo can we get @GrygrFlzr added to the Vercel Slack? it might be easier than going via the support route. |
It seems that AWS Lambda only supports CJS (sdk issue) and so that's the only option for Netlify which relies on Lambda. I guess the only solution is to have at least that adapter transpile with Rollup |
Correspondence with Vercel has ground to a halt for now. I looked into this further - I can make Vercel import module.exports = async (res, req) => {
const { default: app } = await import("./index.mjs");
await app(res, req);
}; But then #324 pops up, despite the fact that Vercel logs{
"errorType": "Runtime.UnhandledPromiseRejection",
"errorMessage": "Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@sveltejs/kit' imported from /var/task/server/app.mjs",
"reason": {
"errorType": "Error",
"errorMessage": "Cannot find package '@sveltejs/kit' imported from /var/task/server/app.mjs",
"code": "ERR_MODULE_NOT_FOUND",
"stack": [
"Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@sveltejs/kit' imported from /var/task/server/app.mjs",
" at packageResolve (internal/modules/esm/resolve.js:655:9)",
" at moduleResolve (internal/modules/esm/resolve.js:696:18)",
" at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:810:11)",
" at Loader.resolve (internal/modules/esm/loader.js:86:40)",
" at Loader.getModuleJob (internal/modules/esm/loader.js:230:28)",
" at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:56:40)",
" at link (internal/modules/esm/module_job.js:55:36)"
]
},
"promise": {},
"stack": [
"Runtime.UnhandledPromiseRejection: Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@sveltejs/kit' imported from /var/task/server/app.mjs",
" at process.<anonymous> (/var/runtime/index.js:35:15)",
" at process.emit (events.js:327:22)",
" at processPromiseRejections (internal/process/promises.js:245:33)",
" at processTicksAndRejections (internal/process/task_queues.js:94:32)"
]
} To summarize:
|
Someone else contacted the Vercel slack and apparently:
Which happens 30th April (end of next month), so that's potentially something to look forward to. We'd probably still have to bundle |
After the (partial) success with getting module.exports = {
async handler(event) {
const { handler } = await import("./index.mjs");
return await handler(event);
},
}; {
"errorType": "Error",
"errorMessage": "Cannot find package '@sveltejs/kit' imported from /var/task/src/app.mjs",
"trace": [
"Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@sveltejs/kit' imported from /var/task/src/app.mjs",
" at packageResolve (internal/modules/esm/resolve.js:650:9)",
" at moduleResolve (internal/modules/esm/resolve.js:691:18)",
" at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:784:11)",
" at Loader.resolve (internal/modules/esm/loader.js:100:40)",
" at Loader.getModuleJob (internal/modules/esm/loader.js:246:28)",
" at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:47:40)",
" at link (internal/modules/esm/module_job.js:46:36)"
]
} It looks like we can skip transpiling to CJS as long as we have a single CJS file acting as the entry point! That should make it easy to migrate to 100% ESM in the future should it be supported by the serverless services. |
This issue can be closed as soon as #483, #485, and #486 all get merged.
|
Closing this as the relevant PRs have been merged. Further discussion should go to #503 instead. |
Do you have a code example for the Vercel example you have here @GrygrFlzr, please? |
Describe the bug
For both Netlify and Vercel, the functions are expected to be in CJS format.
Logs
Netlify
Vercel
To Reproduce
kit/examples
Repeat above with Vercel.
Expected behavior
No import issues.
Information about your SvelteKit Installation:
Severity
This makes the Netlify and Vercel adapters unusable. The user might be able to postprocess the adapter results to CJS themselves, but practically speaking it's a blocker for those platforms.
Additional context
In an ideal world, the lambdas could run ESM, but it seems the adapter output might need to be translated to CJS instead.
This would likely affect all variants of AWS lambdas. AWS recently added Node 14 support but it does not mention supporting ESM imports, so I'm not sure of their stance on it. There's also an open Netlify forum post about it.
#349 is likely related, as this impedes the goal to have everything in ESM.
The text was updated successfully, but these errors were encountered: