{"record":{"id":"f3c67017553f746f","repo":"Kong/insomnia","slug":"the-template-must-be-a-string-or-an-object","errorCode":null,"errorMessage":"The template must be a string or an object","messagePattern":"The template must be a string or an object","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/insomnia-scripting-environment/src/objects/environments.ts","lineNumber":131,"sourceCode":"  };\n\n  /**\n   * Replaces placeholders in the given template string with values from the environment object.\n   *\n   * It supports following placeholders:\n   * - `insomnia.environment.replaceIn(\"My id is {{$randomUUID}}\")`, which generates a random UUID.\n   * - `insomnia.environment.replaceIn(\"Visiting URL: {{urlValueFromEnvironment}}\")`, which replaces `urlValueFromEnvironment` with the value of that variable in the active environment.\n   *\n   * @param template - The template string containing placeholders to be replaced.\n   * @returns The rendered string with placeholders replaced by their corresponding values.\n   * \n   * @throws Will throw an error if template is not a string or object.\n   */\n  replaceIn = async (template: string | object) => {\n    if (typeof template === 'object') {\n      template = template.toString();\n    } else if (typeof template !== 'string') {\n      throw new TypeError('The template must be a string or an object');\n    }\n\n    return getInterpolator().render(template, this.toObject());\n  };\n\n  /**\n   * Converts the key-value pairs stored in the current instance into a plain JavaScript object.\n   *\n   * @returns {Record<string, any>} A plain object representation of the key-value pairs.\n   */\n  toObject = () => {\n    return Object.fromEntries(this.kvs.entries());\n  };\n\n  toJSON() {\n    return this.toObject();\n  }\n}","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/Kong/insomnia/blob/d9bb2b0142600f21309832daea3317942d285984/packages/insomnia-scripting-environment/src/objects/environments.ts#L113-L149","documentation":"Error \"The template must be a string or an object\" thrown in Kong/insomnia.","triggerScenarios":"Thrown at packages/insomnia-scripting-environment/src/objects/environments.ts:131 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"d9bb2b0142600f21309832daea3317942d285984","analyzedAt":"2026-08-26T18:04:05.187Z","schemaVersion":2},"datasetVersion":"2026-08-26T21:11:00.512Z"}