{"record":{"id":"c428d76f4a2bf9bd","repo":"rolldown/rolldown","slug":"failed-to-generate-d-ts-from-runtime-extra-dev-js","errorCode":null,"errorMessage":"Failed to generate d.ts from runtime-extra-dev.js","messagePattern":"Failed to generate d\\.ts from runtime-extra-dev\\.js","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/rolldown/build.ts","lineNumber":291,"sourceCode":"  );\n\n  const result = ts.transpileDeclaration(commonRuntimeSource, {\n    compilerOptions: {\n      ...getTsconfigCompilerOptionsForFile(commonRuntimeInputFile),\n      noEmit: false,\n      emitDeclarationOnly: true,\n    },\n    fileName: commonRuntimeInputFile,\n  });\n\n  if (result && result.outputText) {\n    fs.writeFileSync(outputFile, result.outputText, 'utf-8');\n    fs.copyFileSync(\n      outputFile,\n      nodePath.resolve(buildMeta.buildOutputDir, 'experimental-runtime-types.d.ts'),\n    );\n  } else {\n    throw new Error('Failed to generate d.ts from runtime-extra-dev.js');\n  }\n}\n\nfunction readDevRuntimeSources() {\n  return {\n    commonRuntimeSource: fs.readFileSync(commonRuntimeInputFile, 'utf-8'),\n    defaultRuntimeSource: fs.readFileSync(defaultRuntimeInputFile, 'utf-8'),\n  };\n}\n\nfunction readDefaultDevRuntimeSource() {\n  const { commonRuntimeSource, defaultRuntimeSource } = readDevRuntimeSources();\n  return `${commonRuntimeSource}\\n${defaultRuntimeSource}`;\n}\n\nfunction getTsconfigCompilerOptionsForFile(file: string) {\n  const tsconfigPath = ts.findConfigFile(file, (path) => ts.sys.fileExists(path));\n  let compilerOptions = ts.getDefaultCompilerOptions();","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/rolldown/rolldown/blob/91b44b9d7bcfb5725533478e044e3891a251b2c5/packages/rolldown/build.ts#L273-L309","documentation":"packages/rolldown/build.ts generates TypeScript declarations for the experimental runtime by running the TypeScript compiler over runtime-extra-dev.js. If the emit produces no outputText (the transpile/emit returned nothing usable), the script throws this error to fail the build loudly rather than shipping missing or empty d.ts files.","triggerScenarios":"generateRuntimeEntry calls the TypeScript API on runtime-extra-dev.js and the result's outputText is falsy (emit skipped, wrong input file, or ts configuration mismatch), so the else branch throws.","commonSituations":"Upgrading TypeScript changes emit behavior; the runtime source file is renamed/moved so the compiled input is empty or wrong; tsconfig options (declaration/emit settings) incompatible with the inline transpile call.","solutions":["Verify runtime-extra-dev.js exists at the expected path and is non-empty","Log the ts.emit/transpile result and diagnostics to find why outputText is empty","Check the TypeScript version and the compilerOptions used for the emit (target/module must be emit-compatible)","Re-run the build after fixing; if caused by an upstream change, update generateRuntimeEntry to the new TS API"],"exampleFix":"// before\nconst result = ts.transpileModule(src, { compilerOptions });\nif (result.outputText) { /* write */ } else { throw new Error('Failed to generate d.ts from runtime-extra-dev.js'); }\n// after: surface diagnostics\nconst result = ts.transpileModule(src, { compilerOptions, reportDiagnostics: true });\nif (result.diagnostics?.length) console.error(result.diagnostics);\nif (!result.outputText) throw new Error(`Failed to generate d.ts from runtime-extra-dev.js: ${file} (${src.length} bytes)`);","handlingStrategy":"try-catch","validationCode":"// before generating, check input exists and is non-empty\nif (!fs.existsSync(runtimeExtraDev) || fs.statSync(runtimeExtraDev).size === 0) {\n  throw new Error(`runtime-extra-dev.js missing or empty at ${runtimeExtraDev}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  generateRuntimeEntry();\n} catch (e) {\n  if (String(e).includes('Failed to generate d.ts')) {\n    console.error('TS emit produced no output; check runtime source and TS version');\n    process.exit(1);\n  }\n  throw e;\n}","preventionTips":["Pin/verify the TypeScript version used by the build","Log diagnostics from the TS API on every emit","Keep runtime source paths in one constant module so renames update everywhere"],"tags":["build-script","typescript","code-generation","dts"],"backgroundTag":"file-write-failed","analyzedSha":"91b44b9d7bcfb5725533478e044e3891a251b2c5","analyzedAt":"2026-09-07T16:04:13.504Z","contentChangedAt":"2026-09-07T16:04:13.504Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}