Kong/insomnia · error · TypeError

The template must be a string or an object

Error message

The template must be a string or an object

What it means

Error "The template must be a string or an object" thrown in Kong/insomnia.

Source

Thrown at packages/insomnia-scripting-environment/src/objects/environments.ts:131

  };

  /**
   * Replaces placeholders in the given template string with values from the environment object.
   *
   * It supports following placeholders:
   * - `insomnia.environment.replaceIn("My id is {{$randomUUID}}")`, which generates a random UUID.
   * - `insomnia.environment.replaceIn("Visiting URL: {{urlValueFromEnvironment}}")`, which replaces `urlValueFromEnvironment` with the value of that variable in the active environment.
   *
   * @param template - The template string containing placeholders to be replaced.
   * @returns The rendered string with placeholders replaced by their corresponding values.
   * 
   * @throws Will throw an error if template is not a string or object.
   */
  replaceIn = async (template: string | object) => {
    if (typeof template === 'object') {
      template = template.toString();
    } else if (typeof template !== 'string') {
      throw new TypeError('The template must be a string or an object');
    }

    return getInterpolator().render(template, this.toObject());
  };

  /**
   * Converts the key-value pairs stored in the current instance into a plain JavaScript object.
   *
   * @returns {Record<string, any>} A plain object representation of the key-value pairs.
   */
  toObject = () => {
    return Object.fromEntries(this.kvs.entries());
  };

  toJSON() {
    return this.toObject();
  }
}

View on GitHub (pinned to d9bb2b0142)

When it happens

Trigger: Thrown at packages/insomnia-scripting-environment/src/objects/environments.ts:131 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Kong/insomnia@d9bb2b0142 (2026-08-26). Data as JSON: /api/errors/f3c67017553f746f. Report an issue: GitHub.