denoland/deno · error
Type checking failed when generating declarations:\n{}
Error message
Type checking failed when generating declarations:\n{} What it means
deno bundle --declaration runs the TypeScript compiler over the entry's module graph to emit .d.ts files (type_checker.emit_declarations, cli/tools/bundle/mod.rs:460-466). If tsc produces any diagnostics, the run fails with them appended after this message - the same class of errors deno check reports, surfaced from bundling.
Source
Thrown at cli/tools/bundle/mod.rs:469
specifiers,
crate::graph_util::BuildGraphWithNpmOptions {
is_dynamic: false,
loader: None,
npm_caching: cli_options.default_npm_caching_strategy(),
},
)
.await?;
// Run type checker to emit declaration files
let type_checker = factory.type_checker().await?;
let result = type_checker.emit_declarations(
Arc::new(graph),
root_names,
cli_options.ts_type_lib_window(),
)?;
if result.diagnostics.has_diagnostic() {
deno_core::anyhow::bail!(
"Type checking failed when generating declarations:\n{}",
result.diagnostics
);
}
// Index emitted .d.ts files by their original source specifier
// TSC emits keys like "file:///path/to/file.d.ts" - map them back to source paths
let mut dts_by_source: std::collections::HashMap<String, String> =
std::collections::HashMap::new();
for (file_name, content) in &result.emitted_files {
// Map "file:///path/to/mod.d.ts" -> normalized source path
if let Ok(specifier) = Url::parse(file_name)
&& let Ok(file_path) = specifier.to_file_path()
{
let source_path = file_path.to_string_lossy().to_string();
dts_by_source.insert(source_path, content.clone());
}
}View on GitHub (pinned to 89f33cbef2)
Solutions
- Run 'deno check <entry>' and fix the reported type errors there first - it iterates faster than bundling
- Ensure npm:/jsr: dependencies expose types (prefer @types/ packages where the base package is untyped)
- Loosen the specific code: correct the typing rather than suppressing; as a last resort annotate with @ts-ignore/@ts-expect-error at the exact sites listed in the diagnostics
- If the declaration artifact isn't required, drop the --declaration flag from the build step
Example fix
# before deno bundle --declaration src/lib/main.ts --outdir dist # fails: Type checking failed when generating declarations # after: iterate on errors first, then bundle deno check src/lib/main.ts # fix everything reported here first deno bundle --declaration src/lib/main.ts --outdir dist
Defensive patterns
Strategy: validation
Validate before calling
# Validate type-cleanness before the declaration bundle step
deno check src/lib/main.ts || { echo 'fix type errors before --declaration'; exit 1; }
deno bundle --declaration src/lib/main.ts --outdir dist Try / catch
# CI: run declaration bundling only when the graph type-checks if deno check src/lib/main.ts; then deno bundle --declaration src/lib/main.ts --outdir dist; else echo 'skipping --declaration: type errors present'; exit 1; fi
Prevention
- Make 'deno check' a required CI step ahead of any --declaration bundle
- Prefer typed dependencies (jsr:, @types/) so the graph has declarations to emit
- Keep strictness increases paired with a fix pass in the same change
When it happens
Trigger: Any type error in the entry's graph (TS2322 assignments, TS2339 property access, TS2307 missing modules with types missing); npm/jsr dependencies that ship no or broken types; tsconfig compilerOptions (strictness, lib) making previously-passing code fail.
Common situations: Libraries bundling artifacts with --declaration in CI where local editor checks were skipped; a dependency update changing types; strict mode enabled via deno.json compilerOptions turning previously silent issues into errors.
Related errors
- No declaration file emitted for entry point: {}
- Entry point must be a file: {}
- The bench function must have a name
- ${prefix}Linter plugin name must be a string
- Invalid cron schedule: start=${start}, end=${end}, every=${e
AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16).
Data as JSON: /api/errors/620045b69a0e1bbb.
Report an issue: GitHub.