sveltejs/kit · error

Invalid alias value

Error message

Invalid alias value: ${value}

What it means

Each kit.alias value must be a plain relative path, optionally ending in `/*` or a file extension (alias_value = /^(.+?)((\/\*)|(\.\w+))?$/). Values like absolute paths with odd segments, URLs, or values with unsupported suffixes fail this regex, and sync throws before writing the tsconfig paths.

Solutions

  1. Change the alias value to a simple relative path without a leading './' or trailing slash: 'src/lib' instead of './src/lib/'.
  2. For wildcard aliases pair the key and value with `/*`: '$lib/*': 'src/lib/*'.
  3. Remove non-path values (URLs, absolute paths) from kit.alias — aliases must point inside the project.

Example fix

// before (svelte.config.js)
alias: { '$utils': './src/utils/', '$cdn': 'https://cdn.example.com' }
// after
alias: { '$utils': 'src/utils', '$utils/*': 'src/utils/*' }
Defensive patterns

Strategy: validation

Validate before calling

const ALIAS_VALUE = /^(.+?)((\/\*)|(\.\w+))?$/;
for (const value of Object.values(config.kit?.alias ?? {})) {
  if (!ALIAS_VALUE.test(value)) throw new Error(`Invalid kit.alias value: ${value}`);
}

Type guard

function isValidAliasValue(value) {
  return typeof value === 'string' && value.length > 0 && /^(.+?)((\/\*)|(\.\w+))?$/.test(value);
}

Try / catch

try {
  await runSync();
} catch (e) {
  if (e.message.startsWith('Invalid alias value')) {
    console.error('Fix kit.alias in svelte.config.js:', e.message);
  }
  throw e;
}

Prevention

When it happens

Trigger: kit.alias values such as 'https://example.com/lib', '/abs/path', './src/lib/', or 'src/lib.d' patterns that don't conform — anything not matching a relative path with optional /* or extension suffix.

Common situations: Copy-pasting alias values from webpack configs; accidentally adding trailing slashes; including protocol prefixes or leading './' variants that confuse the validation; typos in the path.

Related errors


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

Appendix: source

Thrown at packages/kit/src/core/sync/write_tsconfig/index.js:256

 *
 * @param {import('types').ValidatedConfig} config
 * @param {string} root
 * @returns {Record<string, string[]>}
 */
function get_paths(config, root) {
	const alias = {
		...config.alias
	};

	/** @type {Record<string, string[]>} */
	const paths = {};

	for (const [key, value] of Object.entries(alias)) {
		const key_match = alias_key.exec(key);
		if (!key_match) throw new Error(`Invalid alias key: ${key}`);

		const value_match = alias_value.exec(value);
		if (!value_match) throw new Error(`Invalid alias value: ${value}`);

		const resolved = path.resolve(root, remove_trailing_slashstar(value));
		const slashstar = key_match[2];

		if (slashstar) {
			paths[key] = [resolved + '/*'];
		} else {
			paths[key] = [resolved];
			const fileending = value_match[4];

			if (!fileending && !(key + '/*' in alias)) {
				paths[key + '/*'] = [resolved + '/*'];
			}
		}
	}

	return paths;
}

View on GitHub (pinned to 03f1687fe6)