denoland/deno · error

Failed to install "{}" specifier. If you are trying to insta

Error message

Failed to install "{}" specifier. If you are trying to install {} globally, run again with `-g` flag:
  deno install -g {}

What it means

When a local add-style install receives exactly one package argument that parses as an http/https URL, Deno refuses it: remote URL scripts are not project dependencies (they don't go in deno.json/package.json), they are global executables. The error names the scheme ('http'/'https') and suggests the global form.

Source

Thrown at cli/tools/installer/local.rs:502

    log::info!("  installed {} jsr package(s)", installed.len());
  }
  Ok(())
}

pub fn check_if_installs_a_single_package_globally(
  maybe_add_flags: Option<&AddFlags>,
) -> Result<(), AnyError> {
  let Some(add_flags) = maybe_add_flags else {
    return Ok(());
  };
  if add_flags.packages.len() != 1 {
    return Ok(());
  }
  let Ok(url) = Url::parse(&add_flags.packages[0]) else {
    return Ok(());
  };
  if matches!(url.scheme(), "http" | "https") {
    bail!(
      "Failed to install \"{}\" specifier. If you are trying to install {} globally, run again with `-g` flag:\n  deno install -g {}",
      url.scheme(),
      url.as_str(),
      url.as_str()
    );
  }
  Ok(())
}

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Install it globally: `deno install -g <https-url>`
  2. If you wanted a project dependency, add the real package instead: `deno add npm:<pkg>` or `deno add jsr:<pkg>`
  3. For one-off runs without installing, use `deno run <https-url>`

Example fix

# before
deno add https://example.com/tool.ts

# after (global executable)
deno install -g https://example.com/tool.ts

# after (project dependency instead)
deno add npm:chalk
Defensive patterns

Strategy: validation

Validate before calling

# route by scheme before invoking install/add:
if [[ "$spec" == https://* || "$spec" == http://* ]]; then deno install -g "$spec"; else deno add "$spec"; fi

Type guard

// JS
const isRemoteScript = (s) => /^https?:\/\//.test(s);
// if (isRemoteScript(spec)) -> deno install -g spec, else deno add spec

Try / catch

Catch the 'Failed to install "https" specifier' bail and re-run the exact `deno install -g <url>` command the message prints.

Prevention

When it happens

Trigger: Conditions at cli/tools/installer/local.rs:502: exactly one package in add_flags, Url::parse succeeds, and url.scheme() is http or https. E.g. `deno add https://example.com/tool.ts` or `deno install <url>` in local mode.

Common situations: Users migrating from `deno install https://...` one-off tool installs; trying to 'add' a CDN script as a dependency instead of using an npm:/jsr: package.

Related errors


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