sveltejs/kit · error · Error

Cannot import ${normalized} into code that runs in the brows

Error message

Cannot import ${normalized} into code that runs in the browser, as this could leak sensitive information.\n\n${pyramid}\n\nIf you're only using the import as a type, change it to `import type`.

What it means

Error "Cannot import ${normalized} into code that runs in the browser, as this could leak sensitive information.\n\n${pyramid}\n\nIf you're only using the import as a type, change it to `import type`." thrown in sveltejs/kit.

Source

Thrown at packages/kit/src/exports/vite/plugins/guard.js:204

				const chain = find_chain(normalized, [normalized]);

				if (chain) {
					if (chain.some((id) => remote_module_pattern.test(id))) {
						error_for_missing_config('remote functions', 'experimental.remoteFunctions', 'true');
					}

					const pyramid = chain
						.reverse()
						.map((id, i) => {
							return `${' '.repeat(i + 1)}${id}`;
						})
						.join(' imports\n');

					let message = `Cannot import ${normalized} into code that runs in the browser, as this could leak sensitive information.`;
					message += `\n\n${pyramid}`;
					message += `\n\nIf you're only using the import as a type, change it to \`import type\`.`;

					throw stackless(message);
				}

				// No chain from this server-only module to a client entrypoint was found —
				// the module is only imported from server code, which is valid.
			}
		},

		// avoid watch mode rebuilds using stale import map data
		buildEnd() {
			import_map.clear();
		}
	};
}

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Move the browser-facing code so it no longer (transitively) imports the $lib/server or .server.js module
  2. If the import is types-only, change it to `import type`
  3. Split shared logic out of the server module into a neutral module both sides can import
  4. Enable experimental.remoteFunctions if the import is a remote module used intentionally
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/kit/src/exports/vite/plugins/guard.js:204 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/62b7eb85bff8c0f0. Report an issue: GitHub.