denoland/deno · error · AnyError

Cannot represent compiler option

Error message

Cannot represent compiler option '{name}' as a generated JSX pragma.

What it means

While 'unfurling' sources during `deno publish`, Deno rewrites per-file compiler options into a leading comment pragma (e.g. `/** @jsxImportSource react */`). A pragma is unquoted source text, so the value must be safe to embed: non-empty, no `*/` (would close the comment), and no whitespace or control characters (checked by `is_safe_unquoted_comment_value`). If a JSX-related compiler option value violates those rules, Deno cannot represent it and fails with this error.

Solutions

  1. Fix the offending compiler option in deno.json to be a plain identifier/specifier with no whitespace: `"jsxImportSource": "react"` (or your runtime package).
  2. Check jsxFactory/jsxFragmentFactory values too — they must be valid unquoted pragma tokens (letters, digits, `_`, `$`, `.`, `/`, `-`).
  3. Remove an empty-string JSX option instead of setting it to "".
  4. Re-run `deno publish --dry-run` to confirm unfurling succeeds.

Example fix

// before (deno.json)
{
  "compilerOptions": {
    "jsxImportSource": "preact/compat "
  }
}

// after
{
  "compilerOptions": {
    "jsxImportSource": "preact/compat"
  }
}
Defensive patterns

Strategy: validation

Validate before calling

function isSafePragmaValue(v: string): boolean {
  return v.length > 0 &&
    !v.includes('*/') &&
    ![...v].some((c) => /\s|\p{Cc}/u.test(c));
}

const jsxImportSource = denoJson.compilerOptions?.jsxImportSource ?? '';
if (!isSafePragmaValue(jsxImportSource)) {
  throw new Error(`jsxImportSource cannot be embedded as a pragma: ${jsxImportSource}`);
}

Type guard

const isSafePragmaValue = (v: string): boolean =>
  v.length > 0 && !v.includes('*/') && !/\s|\p{Cc}/u.test(v);

Try / catch

try {
  await runDeno(['publish']);
} catch (e) {
  if (String(e.message).includes('generated JSX pragma')) {
    // normalize the offending JSX option in deno.json (strip whitespace/`*/`) and retry
  }
}

Prevention

When it happens

Trigger: `"jsxImportSource": "my lib"` (space inside the specifier); a jsxFactory/jsxFragmentFactory value containing whitespace or `*/`; an empty value for one of these options in deno.json or a per-file pragma that publish tries to regenerate.

Common situations: Copying a JSX config from a bundler where free-form strings are allowed; editor auto-inserting a trailing space into jsxImportSource; unusual jsxFactory names with spaces. Only surfaces during publish because that is when pragmas are generated for the shipped tarball.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/6ec532ec77b32995. Report an issue: GitHub.

Appendix: source

Thrown at cli/tools/publish/module_content.rs:32

use deno_graph::ModuleGraph;
use deno_resolver::cache::LazyGraphSourceParser;
use deno_resolver::cache::ParsedSourceCache;
use deno_resolver::deno_json::CompilerOptionsResolver;
use deno_resolver::workspace::ResolutionKind;
use lazy_regex::Lazy;

use super::diagnostics::PublishDiagnostic;
use super::diagnostics::PublishDiagnosticsCollector;
use super::unfurl::PositionOrSourceRangeRef;
use super::unfurl::SpecifierUnfurler;
use super::unfurl::SpecifierUnfurlerDiagnostic;
use super::unfurl::SpecifierUnfurlerSys;
use crate::sys::CliSys;
use crate::tools::unfurl_utils::is_safe_unquoted_comment_value;

fn jsx_pragma(name: &str, value: &str) -> Result<String, AnyError> {
  if !is_safe_unquoted_comment_value(value) {
    return Err(deno_core::anyhow::anyhow!(
      "Cannot represent compiler option '{name}' as a generated JSX pragma."
    ));
  }
  Ok(format!("/** @{name} {value} */"))
}

struct JsxFolderOptions<'a> {
  jsx_runtime: &'static str,
  jsx_classic: Option<Cow<'a, deno_ast::JsxClassicOptions>>,
  jsx_import_source: Option<String>,
  jsx_import_source_types: Option<String>,
}

#[sys_traits::auto_impl]
pub trait ModuleContentProviderSys: SpecifierUnfurlerSys {}

pub struct ModuleContentProvider<TSys: ModuleContentProviderSys = CliSys> {
  specifier_unfurler: SpecifierUnfurler<TSys>,

View on GitHub (pinned to 9ad36f7a2c)