{"record":{"id":"f02938a52b6b6aa2","repo":"withastro/astro","slug":"the-typescript-tsdk-init-option-is-required-it","errorCode":null,"errorMessage":"The `typescript.tsdk` init option is required. It should point to a directory containing a `typescript.js` or `tsserverlibrary.js` file, such as `node_modules/typescript/lib`.","messagePattern":"The `typescript\\.tsdk` init option is required\\. It should point to a directory containing a `typescript\\.js` or `tsserverlibrary\\.js` file, such as `node_modules/typescript/lib`\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/language-tools/language-server/src/nodeServer.ts","lineNumber":31,"sourceCode":"\ttype CollectionConfigInstance,\n\tSUPPORTED_FRONTMATTER_EXTENSIONS_KEYS,\n} from './core/frontmatterHolders.js';\nimport { addAstroTypes } from './core/index.js';\nimport { getLanguagePlugins, getLanguageServicePlugins } from './languageServerPlugin.js';\nimport { getAstroInstall } from './utils.js';\n\nconst connection = createConnection();\nconst server = createServer(connection);\n\nlet contentIntellisenseEnabled = false;\n\nconnection.listen();\n\nconnection.onInitialize((params) => {\n\tconst tsdk = params.initializationOptions?.typescript?.tsdk;\n\n\tif (!tsdk) {\n\t\tthrow new Error(\n\t\t\t'The `typescript.tsdk` init option is required. It should point to a directory containing a `typescript.js` or `tsserverlibrary.js` file, such as `node_modules/typescript/lib`.',\n\t\t);\n\t}\n\n\tconst { typescript, diagnosticMessages } = loadTsdkByPath(tsdk, params.locale);\n\n\tcontentIntellisenseEnabled = params.initializationOptions?.contentIntellisense ?? false;\n\tconst collectionConfig = {\n\t\treload(folders) {\n\t\t\tthis.configs = loadCollectionConfig(folders);\n\t\t},\n\t\tconfigs: contentIntellisenseEnabled\n\t\t\t? loadCollectionConfig(\n\t\t\t\t\t// The vast majority of clients support workspaceFolders, but sometimes some unusual environments like tests don't\n\t\t\t\t\t// @ts-expect-error - Just deprecated types, it's fine\n\t\t\t\t\tparams.workspaceFolders ?? (params.rootUri ? [{ uri: params.rootUri }] : []) ?? [],\n\t\t\t\t)\n\t\t\t: [],","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/language-tools/language-server/src/nodeServer.ts#L13-L49","documentation":"Thrown by the Astro language server's Node server (`nodeServer.ts`) on LSP `initialize` when the client did not pass `initializationOptions.typescript.tsdk`. The server needs a TypeScript lib directory to load `typescript.js`/`tsserverlibrary.js` for language features; without it the server cannot start.","triggerScenarios":"An editor/LSP client starting `@astrojs/language-server`/`astro-languageserver` without sending `initializationOptions.typescript.tsdk` in the `initialize` request. A misconfigured editor extension. A custom LSP wrapper that omits init options.","commonSituations":"Using a non-standard editor integration that doesn't set the tsdk. The VS Code Astro extension failing to forward the tsdk. Programmatic embedding of the language server without init options.","solutions":["Configure the LSP client to send `initializationOptions: { typescript: { tsdk: '<workspace>/node_modules/typescript/lib' } }`.","Use the official Astro editor extension, which sets this automatically.","Ensure `typescript` is installed in the workspace so the lib path resolves."],"exampleFix":"// before: language client init without options\nconst client = new LanguageClient({ id: 'astro', serverOptions });\n// after\nconst client = new LanguageClient({\n  id: 'astro',\n  serverOptions,\n  clientOptions: {\n    initializationOptions: {\n      typescript: { tsdk: require('path').dirname(require.resolve('typescript')) },\n    },\n  },\n});","handlingStrategy":"validation","validationCode":"function assertTsdk(init: any) {\n  if (!init?.typescript?.tsdk) {\n    throw new Error('Client must send initializationOptions.typescript.tsdk');;\n  }\n}","typeGuard":"function hasTsdk(init: unknown): init is { typescript: { tsdk: string } } {\n  return typeof (init as any)?.typescript?.tsdk === 'string';\n}","tryCatchPattern":null,"preventionTips":["Use the official Astro editor extension which sets tsdk automatically.","In custom LSP clients, always forward `initializationOptions.typescript.tsdk`.","Ensure `typescript` is installed in the workspace so the lib path resolves."],"tags":["language-tools","lsp","typescript","editor","initialization"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}