ESM dependency preventing SvelteKit site from functioning after build completes

This is a known issue on the SvelteKit side but I haven’t seen any mention of it here. I am wondering if there is something I could do with my Netlify configuration that might help. I will outline the problem and all the fixes I have tried. Any help is a appreciated.

There is a good chance that this will get fixed from the Svelte side but am wondering if there is anything I can do in the meantime. I have a big update to my site I would like to publish but some of the routes won’t work because of this bug.

Here is the short timeline of the situation:

A recent update of a SvelteKit dependency has been causing errors for SSR routes. Here is the current github issue on the SvelteKit repo:

Everything builds fine on Netlify but errors after publish with

Error - No "exports" main defined in /var/task/node_modules/devalue/package.json

After this was posted, Rich pushed a change to ‘devalue’ that added a main field to the package.json - which should fix the problem? Here is the commit:

But even after manually forcing the most recent version of Devalue to be included in my project via package.json - I still got the same error in my functions logs.

I also tried changing the project to use Edge functions via

I also tried reverting back to the normal render function and using: devalue cause crash on Netlify after update · Issue #6462 · sveltejs/kit · GitHub

I also tried adding this to my netlify.toml:

node_bundler = "esbuild"

I don’t get the “No “exports” main” error anymore in my render logs but the data won’t load.

Link to my most recent deploy that doesn’t work:
(the static rendered pages work fine)

Example of a route that doesn’t work:

I don’t know if there is anything to do from your side but I thought I would at least try reaching out and letting you guys know what is happening. I’m sure a lot more sites will be affected by this if it isn’t fixed soon on the svelte side.


I noticed in the first link that you posted to the svelte issue that the most recent reply includes a possible solution that worked for another user. Is this something that you could try implementing as well?

Here is the comment I am talking about:

I saw you mentioned trying the first part of this solution, but did this part also apply to you? I added 'devalue' to the ssr.noExternal array in the Vite config? If not, we can go on from there and I can investigate a bit as to whether this is something we can influence on our end.


I tried everything in that thread and some things not in that thread as listed above.

1 Like

Hey, could you explain a little what did you try? What were you able to rule out as causes? Did you get any unexpected results? Please share your process, as this helps us troubleshoot.

1 Like

Sure here is a more detailed list of the fixes I tried. I will reiterate that with all of these fixes I tried, the site built and ran locally using vite build && vite preview - they also all built on Netlify with out problems. It was only after publishing that there was a problem.

Fix 1
Manually including the most recent version of the culprit package ‘devalue’ in my package.json dev dependencies. In sveltekit, everything is a dev dependency. This should’ve fixed the problem since it addressed the error that I saw in my render.js function logs.

It did stop the error from showing up but didn’t help the data load.

Fix 2
I changed the project to use Netlify’s Edge functions by adding this to my netlify.toml

  node_bundler = "esbuild"

and this to my svelte.config.js

/** @type {import('@sveltejs/kit').Config} */
import netlify from '@sveltejs/adapter-netlify';
const config = {
	kit: {
+		adapter: netlify({ edge: true })    // edge fix

export default config;

Fix 3
I kept fix 2 in place but removed ‘devalue’ from my package.json and let it use the version specified in the dependency.

Fix 4
I removed the adapter: netlify({ edge: true }) specification but kept the node_bundler = "esbuild" in place.

Fix 5
I kept the node_bundler = "esbuild" in place and added the most recent ‘devalue’ to my package.json

All of these broke when trying to load dynamic data from a SSR route. I use a mix of pre-rendered pages and dynamic routes… The API code is the same between them. The pre-rendered pages are fine. They make it through the build-step and the content on the pages after build.

There is just something that happens on my dynamic routes at the time of load.

I will reiterate, this all builds and runs fine locally in preview mode. This also builds fine on Netlify. It’s just the live site that is having problems loading data. Other SvelteKit users are encountering the same issue and I have talked to at least 1 other person that the listed fixes won’t work for.

I think I figured out the error and it’s in SvelteKit. I created a bug report and a sample repo for them to look at. Sorry if I caused any confusion for the Netlify engineer team. The bugs I listed above were real, I just had another bug ontop of the ones listed above.

The big upgrades that are happening in the sveltekit world can make things hard to pinpoint where the error is happening. You can mark this as closed for now.

So glad to hear you were able to figure things out and thanks for letting us know we can mark this as closed @Jovian ! :raised_hands: