Create CJS build output, or expect adapters to bundle the ESM themselves?
See original GitHub issueFrom https://github.com/sveltejs/kit/pull/485#issuecomment-797519054:
I almost wonder if adapters should be responsible for bundling the outputted ESM (this would also solve the question of what needs to be considered
external
duringbuild
, so that adapters that target lambda can create a single CJS file.Alternatively maybe Vite could output both ESM and CJS from
build
.
tl;dr most lambda platforms seem to expect CJS, even though Node itself runs ESM natively. The best outcome would probably be if those adapters had access to a single CJS file with no external dependencies (since the platform’s bundlers don’t always work as you’d hope), though the possibility of native modules in the dep graph makes this a bit of a challenge. So exporting CJS from Vite alongside the ESM is probably the easiest solution, even if it’s a bit wasteful.
We could eliminate the waste if the adapter was able to declare its requirements to build
.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
See also: #612
There also seems to be an issue with the node adapter not being able to resolve some modules like firebase:
The same error occurs for packages like rxfire and rxjs. All packages where used in their latest version. I tried using several node versions (14.16.0 & 12.21.0) which did not help.