---
title: "Run a test with extensions | Grafana k6 documentation"
description: "Learn how to run a k6 test with extensions."
---

# Run a test with extensions

There are two different ways to run your k6 test script depending on the k6 extension you want to use: using the automatic extension resolution, or building a custom k6 binary.

## Before you begin

- [Install k6](/docs/k6/next/set-up/install-k6/) v1.2.0 or higher.

## Use automatic extension resolution

It’s as easy as importing them. Example with [xk6-faker](https://github.com/grafana/xk6-faker):

JavaScript ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```javascript
import faker from 'k6/x/faker';

export default function () {
  console.log(faker.person.firstName());
}
```

Then, you can run your script as usual, and k6 automatically detects the extension and loads it:

sh ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```sh
k6 run script.js
```

Shell tab-completion also triggers automatic extension resolution. When you press Tab after typing an extension import path, k6 provisions the extension if it isn’t already available.

### Limitations

- Only works with Official and Community extensions.
- Output extensions aren’t supported.
- Running scripts from stdin isn’t supported.
- Only files with extensions `.js`, `.ts` or `.tar` can be used.

### Disable automatic extension resolution

You can disable this feature by setting the environment variable `K6_AUTO_EXTENSION_RESOLUTION` to `false`. If provided, the previous example fails because k6 can’t load the extension dynamically.

Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```bash
K6_AUTO_EXTENSION_RESOLUTION=false k6 run test.js
```

## Use extensions with a custom k6 binary

To run other extensions (including ones you create), you need to build a custom k6 binary with [xk6](https://github.com/grafana/xk6/).

You can do this locally with Go or use the xk6 Docker image.

go-and-xk6 docker-in-linux

![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

go-and-xk6 ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```go-and-xk6
xk6 build \
  --with github.com/grafana/xk6-sql@v0.0.1 \
  --with github.com/grafana/xk6-output-influxdb
```

docker-in-linux ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```docker-in-linux
docker run --rm -u "$(id -u):$(id -g)" -v "${PWD}:/xk6" grafana/xk6 build \
  --with github.com/grafana/xk6-sql@v0.0.1 \
```

For more details, refer to:

- [Build a k6 binary using Go](/docs/k6/next/extensions/run/build-k6-binary-using-go/)
- [Build a k6 binary using Docker](/docs/k6/next/extensions/run/build-k6-binary-using-docker/)
