question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create CJS build output, or expect adapters to bundle the ESM themselves?

See original GitHub issue

From 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 during build, 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:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Rich-Harriscommented, Mar 30, 2021

See also: #612

2reactions
nhe23commented, Mar 27, 2021

There also seems to be an issue with the node adapter not being able to resolve some modules like firebase: image

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Publish ESM and CJS in a single package - Anthony Fu
A short tutorial of shipping both ESM and CJS dual formats in a single NPM package.
Read more >
API - esbuild
#Bundle. Supported by: Build. To bundle a file means to inline any imported dependencies into the file itself. This process is recursive so...
Read more >
Building A JavaScript App VS Building A JavaScript Library
This blog post covers a technical challenge involved in preparing a JavaScript project for release that is often forgotten about until the ...
Read more >
Build A Library With esbuild. How to bundle ESM, IIFE or ...
You can use esbuild to bundle libraries from vanilla JavaScript source files but, at least in this tutorial, we are going to use...
Read more >
Mocha - the fun, simple, flexible JavaScript test framework
js and in the browser, making asynchronous testing simple and fun. Mocha tests run serially, allowing for flexible and accurate reporting, while mapping ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found