Skip to content
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 adapter builds cjs by default #5177

Closed
ghostdevv opened this issue Jun 7, 2022 · 4 comments
Closed

Netlify adapter builds cjs by default #5177

ghostdevv opened this issue Jun 7, 2022 · 4 comments

Comments

@ghostdevv
Copy link
Member

ghostdevv commented Jun 7, 2022

Describe the bug

Currently the netlify adapter builds cjs by default, this is configurable with functions.node_bundler in the netlify.toml. The code for that is below:

https://github.com/sveltejs/kit/blob/master/packages/adapter-netlify/index.js#L72

// for esbuild, use ESM
// for zip-it-and-ship-it, use CJS until https://github.com/netlify/zip-it-and-ship-it/issues/750
const esm = netlify_config?.functions?.node_bundler === 'esbuild';

What I am trying to understand is why, and if it's still required to be this way. It's causing issues for esm only packages (for example any package made with svelte-kit package) because the cjs bundle that uses require is of course unable to import esm.

The esm variable there is used in the netlify adapter, if it's false then esbuild is used to transpile the generated esm by sveltekit into cjs. I am unsure why it needs to be set to esbuild in the netlify.toml because it's a sveltekit adapter doing the transpiling.

What I don't fully understand is where zip-it-and-ship-it comes in or why we are transpiling at all. I also don't understand what parts of netlify do and don't support esm. Hopefully the netlify guys or anyone here will know! I asked @brittneypostma and she is going to get some help from some of the netlify team if possible

Reproduction

I created this repo to show what I mean. It uses a package I made that is esm only. If you remove the netlify.toml OR set the node_bundler to zisi then it will generate CJS and when you visit the site on netlify it breaks

https://github.com/ghostdevv/netlify-sveltekit-esm-only-broke

System Info

@sveltejs/adapter-netlify: next => 1.0.0-next.64 
@sveltejs/kit: next => 1.0.0-next.348

Severity

serious, but I can work around it

@benmccann
Copy link
Member

We're blocked by netlify/zip-it-and-ship-it#749

@brittneypostma
Copy link
Contributor

This may be fixed now @ghostdevv with pr #6666

Other possibly relevant issue with zip-it-and-ship-it: netlify/zip-it-and-ship-it#750

@benmccann
Copy link
Member

yeah, this should be fixed. let me know if that's wrong and we can reopen

@ghostdevv
Copy link
Member Author

awesome!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants