{"record":{"id":"02780fb224cf737f","repo":"microsoft/TypeScript","slug":"option-name-is-a-string-value-tsconfig-json-mu","errorCode":null,"errorMessage":"${option.name} is a string value; tsconfig JSON must be parsed with parseJsonSourceFileConfigFileContent or getParsedCommandLineOfConfigFile before passing to createProgram","messagePattern":"(.+?) is a string value; tsconfig JSON must be parsed with parseJsonSourceFileConfigFileContent or getParsedCommandLineOfConfigFile before passing to createProgram","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/compiler/program.ts","lineNumber":1526,"sourceCode":" * @param options - The compiler options which should be used.\r\n * @param host - The host interacts with the underlying file system.\r\n * @param oldProgram - Reuses an old program structure.\r\n * @param configFileParsingDiagnostics - error during config file parsing\r\n * @returns A 'Program' object.\r\n */\r\nexport function createProgram(rootNames: readonly string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program, configFileParsingDiagnostics?: readonly Diagnostic[]): Program;\r\nexport function createProgram(_rootNamesOrOptions: readonly string[] | CreateProgramOptions, _options?: CompilerOptions, _host?: CompilerHost, _oldProgram?: Program, _configFileParsingDiagnostics?: readonly Diagnostic[]): Program {\r\n    let _createProgramOptions = isArray(_rootNamesOrOptions) ? createCreateProgramOptions(_rootNamesOrOptions, _options!, _host, _oldProgram, _configFileParsingDiagnostics) : _rootNamesOrOptions; // TODO: GH#18217\r\n    const { rootNames, options, configFileParsingDiagnostics, projectReferences, typeScriptVersion, host: createProgramOptionsHost } = _createProgramOptions;\r\n    let { oldProgram } = _createProgramOptions;\r\n    // Stop referencing these objects to ensure GC collects them.\r\n    _createProgramOptions = undefined!;\r\n    _rootNamesOrOptions = undefined!;\r\n\r\n    for (const option of commandLineOptionOfCustomType) {\r\n        if (hasProperty(options, option.name)) {\r\n            if (typeof options[option.name] === \"string\") {\r\n                throw new Error(`${option.name} is a string value; tsconfig JSON must be parsed with parseJsonSourceFileConfigFileContent or getParsedCommandLineOfConfigFile before passing to createProgram`);\r\n            }\r\n        }\r\n    }\r\n\r\n    const reportInvalidIgnoreDeprecations = memoize(() => createOptionValueDiagnostic(\"ignoreDeprecations\", Diagnostics.Invalid_value_for_ignoreDeprecations));\r\n\r\n    let processingDefaultLibFiles: SourceFile[] | undefined;\r\n    let processingOtherFiles: SourceFile[] | undefined;\r\n    let files: SourceFile[];\r\n    let symlinks: SymlinkCache | undefined;\r\n    let typeChecker: TypeChecker;\r\n    let classifiableNames: Set<__String>;\r\n    let filesWithReferencesProcessed: Set<Path> | undefined;\r\n    let cachedBindAndCheckDiagnosticsForFile: Map<Path, readonly Diagnostic[]> | undefined;\r\n    let cachedDeclarationDiagnosticsForFile: Map<Path, readonly DiagnosticWithLocation[]> | undefined;\r\n    const programDiagnostics = createProgramDiagnostics(getCompilerOptionsObjectLiteralSyntax);\r\n\r\n    let automaticTypeDirectiveNames: string[] | undefined;\r","sourceCodeStart":1508,"sourceCodeEnd":1544,"githubUrl":"https://github.com/microsoft/TypeScript/blob/b465fdbfe175304d9b977da137b2c178ae1091d3/src/compiler/program.ts#L1508-L1544","documentation":"Thrown by `ts.createProgram` when a compiler option of custom type (e.g. `target`, `module`, `moduleResolution`, `jsx`, `newLine`, `target`-family enums) is still a raw string. These options must be parsed into their numeric enum form first; a leftover string means the tsconfig JSON was not run through `parseJsonSourceFileConfigFileContent` / `getParsedCommandLineOfConfigFile` / `parseJsonConfigFileContent` before being passed in.","triggerScenarios":"Passing hand-built `CompilerOptions` where a custom-type field is a string literal (e.g. `{ target: \"es2020\" }`), or forwarding raw JSON-derived options straight into `createProgram` without a parsed-config step.","commonSituations":"Custom tooling/build scripts that read tsconfig via `JSON.parse` and pass `options` directly; IDE plugins that construct a program from scratch; migrating from an older TS version that was lenient about this.","solutions":["Parse the config with `ts.parseJsonConfigFileContent` (or `parseJsonSourceFileConfigFileContent`/`getParsedCommandLineOfConfigFile`) and pass `parsed.options` to `createProgram`.","If building options by hand, use the enum: `{ target: ts.ScriptTarget.ES2020 }` instead of a string.","Map known string values through `ts.optionDeclarations`/the relevant parser instead of forwarding them raw."],"exampleFix":"// before\nconst opts = JSON.parse(fs.readFileSync(\"tsconfig.json\", \"utf8\")).compilerOptions;\nconst prog = ts.createProgram([\"a.ts\"], opts); // target/module are strings -> throws\n// after\nconst parsed = ts.parseJsonConfigFileContent(\n  ts.readConfigFile(\"tsconfig.json\", ts.sys.readFile).config,\n  ts.sys,\n  \".\",\n);\nconst prog = ts.createProgram(parsed.fileNames, parsed.options);","handlingStrategy":"validation","validationCode":"// Ensure no custom-type option is a string before calling createProgram:\nfor (const opt of ts.commandLineOptionOfCustomType) {\n  if (opts[opt.name] != null && typeof opts[opt.name] === \"string\") {\n    throw new Error(`${opt.name} must be parsed (run parseJsonConfigFileContent)`);\n  }\n}","typeGuard":"function isParsedOptions(opts: ts.CompilerOptions): boolean {\n  return ts.commandLineOptionOfCustomType.every(o => typeof opts[o.name] !== \"string\");\n}","tryCatchPattern":null,"preventionTips":["Always obtain `CompilerOptions` through `parseJsonConfigFileContent` or `getParsedCommandLineOfConfigFile`, not `JSON.parse`.","When building options by hand, use the `ts.ScriptTarget`/`ts.ModuleKind`/etc. enums.","Add a unit test that feeds a real tsconfig through your toolchain."],"tags":["compiler-api","createprogram","configuration","tsconfig","options"],"backgroundTag":null,"analyzedSha":"b465fdbfe175304d9b977da137b2c178ae1091d3","analyzedAt":"2026-08-12T05:38:42.698Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}