Invalid export 'a' error from layout.server.ts/layout.ts during build process above 2.22.2
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
Description
Describe the bug
We're getting an error about invalid exports in layout files that appears to be a false positive. We have no problem in development mode, only in build.
We got this error when we upgrade SvelteKit from 2.22.2 to above, even the latest 2.27.1, we are getting this error.
Reproduction
Making a reproduction is very hard since we really don't know how to reproduce, we have literally no idea...
Logs
The error occurs during the build process:
node:internal/event_target:1101
process.nextTick(() => { throw err; });
^
Error: Invalid export 'a' in src/routes/+layout.server.ts (valid exports are load, prerender, csr, ssr, trailingSlash, config, or anything with a '_' prefix)
at validate (file:///application/node_modules/.pnpm/@sveltejs+kit@2.27.0_@sveltejs+vite-plugin-svelte@5.1.1_svelte@5.37.3_vite@6.3.5_@types+node@_f7pbfpiqtqavra6y44eihmr6gu/node_modules/@sveltejs/kit/src/utils/exports.js:21:10)
at PageNodes.validate (file:///application/node_modules/.pnpm/@sveltejs+kit@2.27.0_@sveltejs+vite-plugin-svelte@5.1.1_svelte@5.37.3_vite@6.3.5_@types+node@_f7pbfpiqtqavra6y44eihmr6gu/node_modules/@sveltejs/kit/src/utils/page_nodes.js:29:5)
at analyse_page (file:///application/node_modules/.pnpm/@sveltejs+kit@2.27.0_@sveltejs+vite-plugin-svelte@5.1.1_svelte@5.37.3_vite@6.3.5_@types+node@_f7pbfpiqtqavra6y44eihmr6gu/node_modules/@sveltejs/kit/src/core/postbuild/analyse.js:236:8)
at analyse (file:///application/node_modules/.pnpm/@sveltejs+kit@2.27.0_@sveltejs+vite-plugin-svelte@5.1.1_svelte@5.37.3_vite@6.3.5_@types+node@_f7pbfpiqtqavra6y44eihmr6gu/node_modules/@sveltejs/kit/src/core/postbuild/analyse.js:115:4)
at async MessagePort.<anonymous> (file:///application/node_modules/.pnpm/@sveltejs+kit@2.27.0_@sveltejs+vite-plugin-svelte@5.1.1_svelte@5.37.3_vite@6.3.5_@types+node@_f7pbfpiqtqavra6y44eihmr6gu/node_modules/@sveltejs/kit/src/utils/fork.js:23:16)
In file applications/web/.svelte-kit/output/server/entries/pages/_layout.server.ts.js we can see the invalid export:
export {
load$4 as a,
load$3 as b,
load$2 as c,
load$1 as d,
load as e,
load$5 as l,
load$6 as load,
ssr as s
};
System Info
System:
OS: macOS 15.5
CPU: (16) arm64 Apple M3 Max
Memory: 300.17 MB / 48.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.18.0 - ~/.volta/tools/image/node/22.18.0/bin/node
npm: 10.9.3 - ~/.volta/tools/image/node/22.18.0/bin/npm
pnpm: 10.13.1 - ~/.volta/bin/pnpm
bun: 1.2.19 - /opt/homebrew/bin/bun
Browsers:
Chrome: 138.0.7204.184
Safari: 18.5
npmPackages:
@sveltejs/adapter-node: ^5.2.13 => 5.2.13
@sveltejs/kit: 2.27.1 => 2.27.1
@sveltejs/vite-plugin-svelte: ^5.1.1 => 5.1.1
svelte: ^5.37.0 => 5.37.3
vite: ^6.3.5 => 6.3.5
Severity
blocking an upgrade
Additional Information
There is a high chance this issue will directly be closed since there is no reproduction but we are facing this error since a month and many developers on our team tried to fix this issue without any success by reviewing all of our layout files but nothing anormal was found.
Even claude sonnet model tried things without success.
Maybe somebody faced the same error or somebody from the SvelteKit core team can help us to test some modifications.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at src/utils/exports.js, src/utils/page_nodes.js, and src/core/postbuild/analyse.js from the stack trace, then inspect applications/web/.svelte-kit/output/server/entries/pages/_layout.server.ts.js and its generated exports. Compare the generated aliases with the validation rules and use a reproducible build to confirm the invalid-export error no longer appears for valid layout files.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js, vite
- Domain
- build-system, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100