---
title: JavascriptTagInWrongFile
description: 'Identifies JavaScript tags outside section, block, and snippet files.'
source_url:
  html: >-
    https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/javascript-tag-in-wrong-file
  md: >-
    https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/javascript-tag-in-wrong-file.md
api_name: liquid
---

# JavascriptTagInWrongFile

Identifies `{% javascript %}` tags in files where JavaScript tags aren't valid. Theme Check reports a JavaScript tag unless it's in section, block, or snippet files.

JavaScript tags are scoped to reusable theme building blocks, so keep them out of templates, layouts, and other theme files.

***

## Examples

The following examples contain code snippets that either fail or pass this check.

### ✗ Fail

In the following example, `templates/index.liquid` contains a `{% javascript %}` tag:

```liquid
{% javascript %}
customElements.define('template-index', TemplateIndex);
{% endjavascript %}
```

### ✓ Pass

In the following example, `snippets/card.liquid` contains a `{% javascript %}` tag in a snippet file:

```liquid
{% javascript %}
customElements.define('product-card', ProductCard);
{% endjavascript %}
```

***

## Options

The following example contains the default configuration for this check:

```yaml
JavascriptTagInWrongFile:
  enabled: true
  severity: error
```

| Parameter | Description |
| - | - |
| `enabled` | Whether this check is enabled. |
| `severity` | The [severity](https://shopify.dev/docs/storefronts/themes/tools/theme-check/configuration#check-severity) of the check. |

***

## Disabling this check

Disabling this check isn't recommended. If you can't avoid violating the rule, then you should disable the check using the [comment syntax](https://shopify.dev/docs/storefronts/themes/tools/theme-check/configuration#disable-checks-using-liquid-comments). This ensures that you intentionally disable the check for each instance.

```liquid
{% # theme-check-disable JavascriptTagInWrongFile %}
{% javascript %}
customElements.define('template-index', TemplateIndex);
{% endjavascript %}
{% # theme-check-enable JavascriptTagInWrongFile %}
```

***
