denoland/deno · error

`deno ` is not supported when configuration file contains…

Error message

`deno {}` is not supported when configuration file contains an "importMap" field. Inline the import map into the Deno configuration file.
    at {}

What it means

Dependency-mutating commands (`deno add`/`remove`, via cmd_name) refuse to run when the active deno.json still uses the legacy top-level `"importMap"` field. The config updater rewrites deno.json, and external import map files cannot be edited safely, so Deno asks you to inline the map first.

Solutions

  1. Move the map contents into deno.json under `"imports"` and delete the `importMap` field, then re-run the command.
  2. Keep `scopes` too if your map used them: `{ "imports": {...}, "scopes": {...} }`.
  3. Remove the now-unused import.map.json file to avoid confusion.

Example fix

// deno.json (before)
{ "importMap": "./import.map.json" }
// import.map.json
{ "imports": { "foo": "https://example.com/foo/mod.ts" } }
// deno.json (after)
{
  "imports": { "foo": "https://example.com/foo/mod.ts" }
}
Defensive patterns

Strategy: validation

Validate before calling

const cfg = JSON.parse(readFileSync("deno.json", "utf8"));
if ("importMap" in cfg) {
  console.error("deno.json uses legacy top-level 'importMap'; inline it as 'imports' first");
  process.exit(1);
}

Type guard

const usesLegacyImportMap = (cfg: Record<string, unknown>): boolean =>
  "importMap" in cfg;

Prevention

When it happens

Trigger: deno.json contains `"importMap": "./import.map.json"` (top-level field) and you run `deno add ...` or `deno remove ...`. The check reads the `importMap` key on the loaded config object.

Common situations: Older projects predating inline `imports`; migration leftovers; import map maintained as a separate file shared across tools.

Related errors


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

Appendix: source

Thrown at cli/tools/pm/mod.rs:553

pub async fn add(
  flags: Arc<Flags>,
  add_flags: AddFlags,
  cmd_name: AddCommandName,
) -> Result<(), AnyError> {
  let save_exact = add_flags.save_exact;
  let (cli_factory, force_package_json, mut npm_config, mut deno_config) =
    load_configs(
      &flags,
      || add_flags.packages.iter().any(|s| s.starts_with("jsr:")),
      add_flags.package_json,
      true,
    )?;

  if let Some(deno) = &deno_config
    && deno.obj().get("importMap").is_some()
  {
    bail!(
      concat!(
        "`deno {}` is not supported when configuration file contains an \"importMap\" field. ",
        "Inline the import map into the Deno configuration file.\n",
        "    at {}",
      ),
      cmd_name,
      deno.display_path(),
    );
  }

  let start_dir = cli_factory.cli_options()?.start_dir.dir_path();

  // only prefer to add npm deps to `package.json` if there isn't a closer deno.json.
  // example: if deno.json is in the CWD and package.json is in the parent, we should add
  // npm deps to deno.json, since it's closer
  let prefer_npm_config = match (npm_config.as_ref(), deno_config.as_ref()) {
    (Some(npm), Some(deno)) => {
      let npm_distance = path_distance(&npm.path, &start_dir);

View on GitHub (pinned to 9ad36f7a2c)