sveltejs/kit · error

Cannot use server-only files in an app with `router.type ===

Error message

Cannot use server-only files in an app with `router.type === 'hash': ${project_relative}

What it means

Route-tree validation error thrown while walking src/routes: with config.router.type === 'hash', routing happens client-side and every route must be loadable in the browser, so server-only files (e.g. +page.server.js, +server.js, .server.js modules) are not allowed. The error names the offending project-relative file. Fires during manifest generation.

Source

Thrown at packages/kit/src/core/sync/create_manifest_data/index.js:286

				if (file.name.endsWith('.d.ts')) {
					let name = file.name.slice(0, -5);
					const ext = valid_extensions.find((ext) => name.endsWith(ext));
					if (ext) name = name.slice(0, -ext.length);

					if (component_name_pattern.test(name) || module_name_pattern.test(name)) continue;
				}

				const project_relative = posixify(path.relative(cwd, path.join(dir, file.name)));

				const item = analyze(
					project_relative,
					file.name,
					config.extensions,
					config.moduleExtensions
				);

				if (config.router.type === 'hash' && item.kind === 'server') {
					throw new Error(
						`Cannot use server-only files in an app with \`router.type === 'hash': ${project_relative}`
					);
				}

				/**
				 * @param {string} type
				 * @param {string} existing_file
				 */
				function duplicate_files_error(type, existing_file) {
					return new Error(
						`Multiple ${type} files found in ${routes_base}${route.id} : ${path.basename(
							existing_file
						)} and ${file.name}`
					);
				}

				if (item.kind === 'component') {
					if (item.is_error) {

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Remove or rename the server-only file (drop the .server suffix, or delete +server.js/+page.server.js)
  2. Switch the router type back to 'pathname' if server routes are required
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/kit/src/core/sync/create_manifest_data/index.js:286 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02). Data as JSON: /api/errors/b56f5263594d42da. Report an issue: GitHub.