Sveltekit site builds fine but returns error on initial page load: trying to import from _app/undefined

Netlify site:

Error from the console: TypeError: Failed to fetch dynamically imported module:

This is a Sveltekit site that returns an error on initial load, but works fine when after navigating. On the initial page load it is calling the start function that tries to load the page and the layout page but for some reason it is referring to /_app/undefined when it should be referring to the __layout page. (I know this because I have looked at a build that worked) You can see this in the image below:

(You can find this in the Sources tab of the Chrome dev tools)

Sveltekit and the Netilify adapter are up to date. The build on Netlify runs successfully. I can build the site locally and it works fine. The last deploy that worked was from Feb 17 at 10:17AM.

I removed the following from the netlify.toml file and it seems to have fixed the problem

node_bundler = “esbuild”

This had been added previously to fix a deploy problem but doesn’t appear to be needed and may even cause problems.

1 Like

Hey there, @bcasey21 :wave:

Thanks so much for coming back and sharing your solution! This will definitely be beneficial to future Forums members.