{"record":{"id":"0ce3a5ef2707c828","repo":"sveltejs/kit","slug":"you-need-to-install-typescript-if-you-want-to-tran","errorCode":null,"errorMessage":"You need to install TypeScript if you want to transpile TypeScript files and/or generate type definitions","messagePattern":"You need to install TypeScript if you want to transpile TypeScript files and/or generate type definitions","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/package/src/typescript.js","lineNumber":217,"sourceCode":"\tconst path = pattern.text.startsWith('!') ? pattern.text.slice(1) : pattern.text;\n\n\tif (!(path.startsWith('./') || path.startsWith('../')) || !path.endsWith('.ts')) {\n\t\treturn pattern;\n\t}\n\n\tconst rewritten = pattern.text.slice(0, -3) + '.js';\n\tconst literal = ts.isStringLiteral(pattern)\n\t\t? ts.factory.createStringLiteral(rewritten, pattern.getText().startsWith(\"'\"))\n\t\t: ts.factory.createNoSubstitutionTemplateLiteral(rewritten);\n\n\treturn ts.setTextRange(literal, pattern);\n}\n\nasync function try_load_ts() {\n\ttry {\n\t\treturn (await import('typescript')).default;\n\t} catch {\n\t\tthrow new Error(\n\t\t\t'You need to install TypeScript if you want to transpile TypeScript files and/or generate type definitions'\n\t\t);\n\t}\n}\n\n/**\n * @param {string | undefined} tsconfig\n * @param {string} filename\n * @param {Map<string, import('typescript').CompilerOptions>} cache\n * @param {typeof import('typescript')} [ts]\n */\nexport async function load_tsconfig(tsconfig, filename, cache, ts) {\n\tif (!ts) {\n\t\tts = await try_load_ts();\n\t}\n\n\tlet config_filename;\n\t/** @type {string[]} */","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/package/src/typescript.js#L199-L235","documentation":"`try_load_ts` dynamically imports the `typescript` package and rethrows any failure as a clear error: @sveltejs/package needs TypeScript itself to transpile TS files or generate .d.ts. TypeScript is an optional peer, so it is not auto-installed with the packager.","triggerScenarios":"Running `svelte-package` on a project that includes `.ts`/`.svelte` files needing transpilation or `types` generation while `typescript` is absent from node_modules (dynamic `import('typescript')` rejects).","commonSituations":"Library repo without typescript in devDependencies; pnpm strict installs where typescript wasn't declared; broken/incompatible typescript install causing the import to fail.","solutions":["Install TypeScript: `npm i -D typescript`.","In pnpm workspaces, declare typescript in the package's devDependencies so it links locally.","Verify `node_modules/typescript` exists and imports cleanly; reinstall node_modules if corrupted."],"exampleFix":"// before\n\"devDependencies\": { \"@sveltejs/package\": \"^2.0.0\" }\n\n// after\n\"devDependencies\": { \"@sveltejs/package\": \"^2.0.0\", \"typescript\": \"^5.0.0\" }","handlingStrategy":"validation","validationCode":"try { await import('typescript'); } catch { throw new Error('add typescript to devDependencies'); }","typeGuard":null,"tryCatchPattern":"try {\n  await run(['svelte-package']);\n} catch (e) {\n  if (String(e.message).includes('You need to install TypeScript')) {\n    throw new Error('Run: npm i -D typescript');\n  }\n  throw e;\n}","preventionTips":["Include typescript in devDependencies whenever the project contains .ts files","Run install after cloning before running build scripts","Keep typescript version within the range supported by @sveltejs/package"],"tags":["typescript","dependencies","transpilation","installation"],"backgroundTag":"typescript-not-installed","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}