|
9 | 9 | icon: 'i-lucide-arrow-right-left'
|
10 | 10 | ---
|
11 | 11 |
|
| 12 | +Nuxt UI v4 marks a major milestone: **Nuxt UI and Nuxt UI Pro are now unified into a single, fully open-source and free library**. You now have access to 100+ production-ready components, all available in the `@nuxt/ui` package. |
| 13 | + |
| 14 | +::note |
| 15 | +Nuxt UI v4 requires **Nuxt 4** due to some dependencies. Make sure to upgrade to Nuxt 4 before migrating to Nuxt UI v4. |
| 16 | +:: |
| 17 | + |
| 18 | +This guide provides step-by-step instructions to migrate your application from v3 to v4. |
| 19 | + |
12 | 20 | ## Migrate your project
|
| 21 | + |
| 22 | +### From Nuxt UI Pro |
| 23 | + |
| 24 | +1. Replace `@nuxt/ui-pro` with `@nuxt/ui` in your `package.json`: |
| 25 | + |
| 26 | +::code-group{sync="pm"} |
| 27 | + |
| 28 | +```bash [pnpm] |
| 29 | +pnpm remove @nuxt/ui-pro |
| 30 | +pnpm add @nuxt/ui@alpha |
| 31 | +``` |
| 32 | + |
| 33 | +```bash [yarn] |
| 34 | +yarn remove @nuxt/ui-pro |
| 35 | +yarn add @nuxt/ui@alpha |
| 36 | +``` |
| 37 | + |
| 38 | +```bash [npm] |
| 39 | +npm uninstall @nuxt/ui-pro |
| 40 | +npm install @nuxt/ui@alpha |
| 41 | +``` |
| 42 | + |
| 43 | +```bash [bun] |
| 44 | +bun remove @nuxt/ui-pro |
| 45 | +bun add @nuxt/ui@alpha |
| 46 | +``` |
| 47 | + |
| 48 | +:: |
| 49 | + |
| 50 | +::framework-only |
| 51 | +#nuxt |
| 52 | +:::div |
| 53 | + |
| 54 | +2. Replace `@nuxt/ui-pro` with `@nuxt/ui` in your `nuxt.config.ts`: |
| 55 | + |
| 56 | +```diff [nuxt.config.ts] |
| 57 | +export default defineNuxtConfig({ |
| 58 | + modules: [ |
| 59 | +- '@nuxt/ui-pro', |
| 60 | ++ '@nuxt/ui' |
| 61 | + ] |
| 62 | +}) |
| 63 | +``` |
| 64 | +::: |
| 65 | + |
| 66 | +#vue |
| 67 | +:::div |
| 68 | + |
| 69 | +2. Replace `@nuxt/ui-pro` with `@nuxt/ui` in your `vite.config.ts`: |
| 70 | + |
| 71 | +```diff [vite.config.ts] |
| 72 | +import { defineConfig } from 'vite' |
| 73 | +import vue from '@vitejs/plugin-vue' |
| 74 | +- import uiPro from '@nuxt/ui-pro/vite' |
| 75 | ++ import ui from '@nuxt/ui/vite' |
| 76 | + |
| 77 | +export default defineConfig({ |
| 78 | + plugins: [ |
| 79 | + vue(), |
| 80 | +- uiPro({ |
| 81 | ++ ui({ |
| 82 | + ui: { |
| 83 | + colors: { |
| 84 | + primary: 'green', |
| 85 | + neutral: 'slate' |
| 86 | + } |
| 87 | + } |
| 88 | + }) |
| 89 | + ] |
| 90 | +}) |
| 91 | +``` |
| 92 | +::: |
| 93 | +:: |
| 94 | + |
| 95 | +::framework-only |
| 96 | +#nuxt |
| 97 | +:::div |
| 98 | +3. Use the `ui` key instead of `uiPro` in your `app.config.ts`: |
| 99 | + |
| 100 | +```diff [app.config.ts] |
| 101 | +export default defineAppConfig({ |
| 102 | + ui: { |
| 103 | + colors: { |
| 104 | + primary: 'green', |
| 105 | + neutral: 'slate' |
| 106 | + }, |
| 107 | ++ pageCard: { |
| 108 | ++ slots: { |
| 109 | ++ root: 'rounded-xl', |
| 110 | ++ } |
| 111 | ++ } |
| 112 | + }, |
| 113 | +- uiPro: { |
| 114 | +- pageCard: { |
| 115 | +- slots: { |
| 116 | +- root: 'rounded-xl', |
| 117 | +- } |
| 118 | +- } |
| 119 | +- } |
| 120 | +}) |
| 121 | +``` |
| 122 | +::: |
| 123 | + |
| 124 | +#vue |
| 125 | +:::div |
| 126 | +3. Use the `ui` key instead of `uiPro` in your `vite.config.ts`: |
| 127 | + |
| 128 | +```diff [vite.config.ts] |
| 129 | +export default defineConfig({ |
| 130 | + plugins: [ |
| 131 | + vue(), |
| 132 | + ui({ |
| 133 | + ui: { |
| 134 | + colors: { |
| 135 | + primary: 'green', |
| 136 | + neutral: 'slate' |
| 137 | + }, |
| 138 | ++ pageCard: { |
| 139 | ++ slots: { |
| 140 | ++ root: 'rounded-xl', |
| 141 | ++ } |
| 142 | ++ } |
| 143 | + }, |
| 144 | +- uiPro: { |
| 145 | +- pageCard: { |
| 146 | +- slots: { |
| 147 | +- root: 'rounded-xl', |
| 148 | +- } |
| 149 | +- } |
| 150 | +- } |
| 151 | + }) |
| 152 | + ] |
| 153 | +}) |
| 154 | +``` |
| 155 | +::: |
| 156 | +:: |
| 157 | + |
| 158 | +4. Replace `@nuxt/ui-pro` with `@nuxt/ui` in your CSS: |
| 159 | + |
| 160 | +::framework-only |
| 161 | +#nuxt |
| 162 | +:::div |
| 163 | +```diff [app/assets/css/main.css] |
| 164 | +@import "tailwindcss"; |
| 165 | +- @import "@nuxt/ui-pro"; |
| 166 | ++ @import "@nuxt/ui"; |
| 167 | +``` |
| 168 | +::: |
| 169 | + |
| 170 | +#vue |
| 171 | +:::div |
| 172 | +```diff [src/assets/css/main.css] |
| 173 | +@import "tailwindcss"; |
| 174 | +- @import "@nuxt/ui-pro"; |
| 175 | ++ @import "@nuxt/ui"; |
| 176 | +``` |
| 177 | +::: |
| 178 | +:: |
| 179 | + |
| 180 | +### From Nuxt UI |
| 181 | + |
| 182 | +1. When upgrading from Nuxt UI v3, you simply need to update to v4: |
| 183 | + |
| 184 | +::code-group{sync="pm"} |
| 185 | + |
| 186 | +```bash [pnpm] |
| 187 | +pnpm add @nuxt/ui@alpha |
| 188 | +``` |
| 189 | + |
| 190 | +```bash [yarn] |
| 191 | +yarn add @nuxt/ui@alpha |
| 192 | +``` |
| 193 | + |
| 194 | +```bash [npm] |
| 195 | +npm install @nuxt/ui@alpha |
| 196 | +``` |
| 197 | + |
| 198 | +```bash [bun] |
| 199 | +bun add @nuxt/ui@alpha |
| 200 | +``` |
| 201 | + |
| 202 | +:: |
| 203 | + |
| 204 | +## Changes from v3 |
| 205 | + |
| 206 | +After upgrading to Nuxt UI v4, please note the following important changes: |
| 207 | + |
| 208 | +### Merged components |
| 209 | + |
| 210 | +Nuxt UI Pro components have been integrated into the main `@nuxt/ui` package. You can keep using them as before, but you now need to import from `@nuxt/ui` instead of `@nuxt/ui-pro`: |
| 211 | + |
| 212 | +```diff |
| 213 | +- import type { BannerProps } from '@nuxt/ui-pro' |
| 214 | ++ import type { BannerProps } from '@nuxt/ui' |
| 215 | +``` |
| 216 | + |
| 217 | +### Renamed components |
| 218 | + |
| 219 | +Several components have been renamed for better consistency: |
| 220 | + |
| 221 | +1. `ButtonGroup` has been replaced with [`FieldGroup`](/docs/components/field-group): |
| 222 | + |
| 223 | +```diff |
| 224 | +<template> |
| 225 | +- <UButtonGroup> |
| 226 | ++ <UFieldGroup> |
| 227 | + <UButton label="Button" /> |
| 228 | + <UButton icon="i-lucide-chevron-down" /> |
| 229 | +- </UButtonGroup> |
| 230 | ++ </UFieldGroup> |
| 231 | +</template> |
| 232 | +``` |
| 233 | + |
| 234 | +2. `PageMarquee` has been replaced with [`Marquee`](/docs/components/marquee): |
| 235 | + |
| 236 | +```diff |
| 237 | +<template> |
| 238 | +- <UPageMarquee :items="items" /> |
| 239 | ++ <UMarquee :items="items" /> |
| 240 | +</template> |
| 241 | +``` |
| 242 | + |
| 243 | +### Removed components |
| 244 | + |
| 245 | +Some components have been removed in favor of more standard alternatives: |
| 246 | + |
| 247 | +1. `PageAccordion` has been replaced with [`Accordion`](/docs/components/accordion): |
| 248 | + |
| 249 | +```diff |
| 250 | +<template> |
| 251 | +- <UPageAccordion :items="faqItems" /> |
| 252 | ++ <UAccordion :items="items" :unmount-on-hide="false" :ui="{ trigger: 'text-base', body: 'text-base text-muted' }" /> |
| 253 | +</template> |
| 254 | +``` |
| 255 | + |
| 256 | +### AI SDK v5 migration (optional) |
| 257 | + |
| 258 | +This section only applies if you're using the AI SDK and chat components (`ChatMessage`, `ChatMessages`, `ChatPrompt`, `ChatPromptSubmit`, `ChatPalette`). If you're not using AI features, you can skip this section. |
| 259 | + |
| 260 | +1. Update `@ai-sdk/vue` and `ai` dependencies in your `package.json`: |
| 261 | + |
| 262 | +```diff |
| 263 | +{ |
| 264 | + "dependencies": { |
| 265 | +- "@ai-sdk/vue": "^1.2.x", |
| 266 | ++ "@ai-sdk/vue": "^2.0.x", |
| 267 | +- "ai": "^4.3.x" |
| 268 | ++ "ai": "^5.0.x" |
| 269 | + } |
| 270 | +} |
| 271 | +``` |
| 272 | + |
| 273 | +2. `useChat` composable has been replaced with the new `Chat` class: |
| 274 | + |
| 275 | +```diff |
| 276 | +<script setup lang="ts"> |
| 277 | +- import { useChat } from '@ai-sdk/vue' |
| 278 | ++ import { Chat } from '@ai-sdk/vue' |
| 279 | ++ import type { UIMessage } from 'ai' |
| 280 | + |
| 281 | +- const { messages, input, handleSubmit, status, error, reload, setMessages } = useChat() |
| 282 | ++ const messages: UIMessage[] = [] |
| 283 | ++ const input = ref('') |
| 284 | ++ |
| 285 | ++ const chat = new Chat({ |
| 286 | ++ messages |
| 287 | ++ }) |
| 288 | ++ |
| 289 | ++ function handleSubmit(e: Event) { |
| 290 | ++ e.preventDefault() |
| 291 | ++ chat.sendMessage({ text: input.value }) |
| 292 | ++ input.value = '' |
| 293 | ++ } |
| 294 | +</script> |
| 295 | +``` |
| 296 | + |
| 297 | +3. Messages now use `parts` instead of `content`: |
| 298 | + |
| 299 | +```diff |
| 300 | +// When manually creating messages |
| 301 | +- setMessages([{ |
| 302 | ++ messages.push({ |
| 303 | + id: '1', |
| 304 | + role: 'user', |
| 305 | +- content: 'Hello world' |
| 306 | ++ parts: [{ type: 'text', text: 'Hello world' }] |
| 307 | +- }]) |
| 308 | ++ }) |
| 309 | + |
| 310 | +// In templates |
| 311 | +<template> |
| 312 | +- <UChatMessage :content="message.content" /> |
| 313 | ++ <UChatMessage :parts="message.parts" /> |
| 314 | +</template> |
| 315 | +``` |
| 316 | + |
| 317 | +4. Some methods have been renamed: |
| 318 | + |
| 319 | +```diff |
| 320 | +// Regenerate the last message |
| 321 | +- reload() |
| 322 | ++ chat.regenerate() |
| 323 | + |
| 324 | +// Access chat state |
| 325 | +- :messages="messages" |
| 326 | +- :status="status" |
| 327 | ++ :messages="chat.messages" |
| 328 | ++ :status="chat.status" |
| 329 | +``` |
| 330 | + |
| 331 | +5. New `getTextFromMessage` utility to extract text from AI SDK v5 message parts: |
| 332 | + |
| 333 | +```vue |
| 334 | +<script setup lang="ts"> |
| 335 | +import { getTextFromMessage } from '@nuxt/ui/utils/ai' |
| 336 | +</script> |
| 337 | +
|
| 338 | +<template> |
| 339 | + <UChatMessages :messages="chat.messages" :status="chat.status"> |
| 340 | + <template #content="{ message }"> |
| 341 | + <!-- Extract text from message parts and render with MDC --> |
| 342 | + <MDC :value="getTextFromMessage(message)" :cache-key="message.id" unwrap="p" /> |
| 343 | + </template> |
| 344 | + </UChatMessages> |
| 345 | +</template> |
| 346 | +``` |
| 347 | + |
| 348 | +::note{to="https://ai-sdk.dev/docs/migration-guides/migration-guide-5-0" target="_blank"} |
| 349 | +For more details on AI SDK v5 changes, review the **official AI SDK v5 migration guide**. |
| 350 | +:: |
| 351 | + |
| 352 | +::tip{to="https://github.com/nuxt/ui/pull/4698" target="_blank"} |
| 353 | +View all changes from AI SDK v4 to v5 **in the upgrade PR** for a detailed migration reference. |
| 354 | +:: |
0 commit comments