denoland/deno · error · anyhow::Error
Cannot generate declarations for files with different compil
Error message
Cannot generate declarations for files with different compiler option scopes.
'{}' uses scope '{}' but '{}' uses scope '{}'.
Separate these files into different invocations. What it means
With `--declaration`, TSC type-checks all root names in a single pass under one set of compiler options. Every file's compiler-options scope (derived from its nearest deno.json/tsconfig) must resolve to the same scope key; any mismatch aborts before checking starts because the results would be inconsistent.
Source
Thrown at cli/tools/transpile.rs:278
specifiers,
crate::graph_util::BuildGraphWithNpmOptions {
is_dynamic: false,
loader: None,
npm_caching: cli_options.default_npm_caching_strategy(),
},
)
.await?;
// Validate that all files share the same compiler options scope, since
// TSC type-checks all files in a single pass.
let compiler_options_resolver = factory.compiler_options_resolver()?;
let first_specifier = &root_names[0].0;
let (first_key, _) =
compiler_options_resolver.entry_for_specifier(first_specifier);
for (specifier, _) in root_names.iter().skip(1) {
let (key, _) = compiler_options_resolver.entry_for_specifier(specifier);
if key != first_key {
anyhow::bail!(
"Cannot generate declarations for files with different compiler option scopes.\n\
'{}' uses scope '{}' but '{}' uses scope '{}'.\n\
Separate these files into different invocations.",
first_specifier,
first_key,
specifier,
key,
);
}
}
let type_checker = factory.type_checker().await?;
let result = type_checker.emit_declarations(
Arc::new(graph),
root_names,
cli_options.ts_type_lib_window(),
)?;
View on GitHub (pinned to 89f33cbef2)
Solutions
- Split into one invocation per scope: run transpile --declaration separately inside each workspace member
- Invoke from a directory where all inputs resolve to a single config scope
- Drop --declaration — plain transpilation does not require matching scopes
Example fix
# before (a.ts and b.ts in different workspace members) deno transpile --declaration packages/one/a.ts packages/two/b.ts # after (cd packages/one && deno transpile --declaration a.ts --outdir dist) (cd packages/two && deno transpile --declaration b.ts --outdir dist)
Defensive patterns
Strategy: validation
Validate before calling
# bash: one invocation per workspace member for member in packages/*/; do (cd "$member" && deno transpile --declaration src/*.ts --outdir dist) || exit 1 done
Prevention
- Never span workspace-member boundaries in a single --declaration invocation
- Group inputs by their nearest deno.json before building the command
- Run plain transpile (no --declaration) when scopes must differ
When it happens
Trigger: `deno transpile --declaration a.ts b.ts` where a.ts and b.ts resolve to different compiler-options scopes — e.g. they sit in different workspace members with per-package deno.json compilerOptions.
Common situations: Monorepos invoking one transpile command across package boundaries; mixing files inside and outside a workspace root that carries its own compilerOptions.
Related errors
- Cannot use --declaration without --output or --outdir. Decla
- Declaration file {} is not under the current directory
- Invalid declaration file path
- No input files specified
- Cannot use --output with multiple input files. Use --outdir
AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16).
Data as JSON: /api/errors/642700600bb69858.
Report an issue: GitHub.