Skip to main content
Skip table of contents

How to remove global variables from templates

The PocketQuery rendering engine validates any JavaScript code in a template to ensure that no unexpected global variables are defined and used. The only global variable that is supported in PocketQuery scripts is the global helper PocketQuery that exposes the PocketQuery JavaScript API. In most cases, global variables are accidentally defined by omitting the let or const declaration.

We are currently logging and displaying a warning for any PocketQuery macro that ends up rendering a script with global variables. For any such warning, please fix the issue in the template. To help you with this, we recommend the online playground of ESLint. After pasting your JavaScript code into the editor, the tool will show you immediately what global variables you defined in your template. There should not be any globals besides the PocketQuery object.

As an example, consider the screenshot below. While the call to PocketQuery.chart(...) uses the global PocketQuery object exposing our JavaScript API (which is ok), it also defines an accidental global myVar (not ok) and uses a global object console (not ok).


For accidental globals in your template: please use the const or let declarations. If you are using global objects that have been working in the past, you will need to find ways to go without these in the future. If you need help with removing or replacing these, feel free to reach out to us.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.