{"record":{"id":"70b5c6b721f87fe3","repo":"sveltejs/kit","slug":"invalid-alias-key-key","errorCode":null,"errorMessage":"Invalid alias key: ${key}","messagePattern":"Invalid alias key: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/kit/src/core/sync/write_tsconfig/index.js","lineNumber":253,"sourceCode":"/**\n * Generates tsconfig path aliases from kit's aliases and the package.json `imports` field.\n * Related to vite alias creation.\n *\n * @param {import('types').ValidatedConfig} config\n * @param {string} root\n * @returns {Record<string, string[]>}\n */\nfunction get_paths(config, root) {\n\tconst alias = {\n\t\t...config.alias\n\t};\n\n\t/** @type {Record<string, string[]>} */\n\tconst paths = {};\n\n\tfor (const [key, value] of Object.entries(alias)) {\n\t\tconst key_match = alias_key.exec(key);\n\t\tif (!key_match) throw new Error(`Invalid alias key: ${key}`);\n\n\t\tconst value_match = alias_value.exec(value);\n\t\tif (!value_match) throw new Error(`Invalid alias value: ${value}`);\n\n\t\tconst resolved = path.resolve(root, remove_trailing_slashstar(value));\n\t\tconst slashstar = key_match[2];\n\n\t\tif (slashstar) {\n\t\t\tpaths[key] = [resolved + '/*'];\n\t\t} else {\n\t\t\tpaths[key] = [resolved];\n\t\t\tconst fileending = value_match[4];\n\n\t\t\tif (!fileending && !(key + '/*' in alias)) {\n\t\t\t\tpaths[key + '/*'] = [resolved + '/*'];\n\t\t\t}\n\t\t}\n\t}","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/core/sync/write_tsconfig/index.js#L235-L271","documentation":"When generating tsconfig path mappings from the SvelteKit `kit.alias` config, each key must look like a valid TS paths pattern, optionally ending in `/*` (alias_key = /^(.+?)(\\/\\*)?$/). A key such as an empty string or a malformed wildcard fails this regex and sync throws during write_tsconfig.","triggerScenarios":"kit.alias entries with invalid keys, e.g. alias: { '': 'src/lib' }, alias: { '*/': 'src' }, or keys containing characters that break the pattern while expecting wildcard semantics in the middle.","commonSituations":"Migrating from webpack-style alias objects where empty or odd keys were tolerated; typos like trailing slashes without the /*; programmatic config generation producing empty keys.","solutions":["Fix the alias key in svelte.config.js to match the TS paths form, e.g. '$lib': 'src/lib' or '$lib/*': 'src/lib/*'.","Remove empty or otherwise invalid keys from kit.alias.","Use the documented $lib alias instead of custom keys when possible, since it is provided automatically."],"exampleFix":"// before (svelte.config.js)\nalias: { '': 'src/lib', 'utils/': 'src/utils' }\n// after\nalias: { '$lib': 'src/lib', 'utils': 'src/utils', 'utils/*': 'src/utils/*' }","handlingStrategy":"validation","validationCode":"const ALIAS_KEY = /^(.+?)(\\/\\*)?$/;\nfor (const key of Object.keys(config.kit?.alias ?? {})) {\n  if (!key || !ALIAS_KEY.test(key)) throw new Error(`Invalid kit.alias key: ${JSON.stringify(key)}`);\n}","typeGuard":"function isValidAliasKey(key) {\n  return typeof key === 'string' && key.length > 0 && /^(.+?)(\\/\\*)?$/.test(key);\n}","tryCatchPattern":"try {\n  await runSync();\n} catch (e) {\n  if (e.message.startsWith('Invalid alias key')) {\n    console.error('Fix kit.alias in svelte.config.js:', e.message);\n  }\n  throw e;\n}","preventionTips":["Use keys of the form 'name' or 'name/*' — no empty strings or stray slashes.","Prefer TypeScript validation of svelte.config.js (defineConfig) to catch bad keys at edit time.","Rely on the built-in $lib alias when possible instead of custom entries."],"tags":["sveltekit","tsconfig","configuration","path-alias"],"backgroundTag":"invalid-alias-config","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}