# Next.js

#### Install the dependencies

Using mosaic requires two packages in your Next.js project - the start script package and the runtime package.

{% tabs %}
{% tab title="yarn" %}

```javascript
yarn add @tilework/mosaic-nextjs-scripts @tilework/mosaic
```

{% endtab %}

{% tab title="npm" %}

```javascript
npm install @tilework/mosaic-nextjs-scripts @tilework/mosaic
```

{% endtab %}
{% endtabs %}

#### Use the new scripts

Replace `next` invocations in the `scripts` block of your package.json. Such way, Next.js will be launched with additional configurations (Webpack and Babel) required for Mosaic.

{% code title="package.json" %}

```diff
{
    "scripts": {
-        "dev": "next",
+        "dev": "nextjs-scripts dev",
-        "build": "next build",
+        "build": "nextjs-scripts build",
-        "start": "next start",
+        "start": "nextjs-scripts start",
               
+        "link": "nextjs-scripts link",
+        "test": "nextjs-scripts test"  
    }
}
```

{% endcode %}

#### Clean up

`next` is a dependency of `mosaic-nextjs-scripts`, thus is no longer needed in your project as a direct dependency. It is advised to remove this redundant dependency.

{% tabs %}
{% tab title="yarn" %}

```diff
yarn remove next
```

{% endtab %}

{% tab title="npm" %}

```diff
npm uninstall next
```

{% endtab %}
{% endtabs %}

&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mosaic.js.org/getting-started/nextjs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
