Open jamie3 opened 2 months ago
It appears the Nuxt 3 Starter template is outdated. In the documentation it is stated you have to initialize when the component gets mounted it looks like it's not enough to use onMounted
because it is possible that document
is not available e.g. during SSR. The following steps worked for me (flowbite 2.5.1
):
# /composable/useFlowbite.ts
export interface FlowbiteInstance {
initAccordions: () => void
initCarousels: () => void
initCollapses: () => void
initDials: () => void
initDismisses: () => void
initDrawers: () => void
initDropdowns: () => void
initModals: () => void
initPopovers: () => void
initTabs: () => void
initTooltips: () => void
initInputCounters: () => void
initCopyClipboards: () => void
initDatepickers: () => void
initFlowbite: () => void
}
export function useFlowbite(callback: (flowbite: FlowbiteInstance) => void) {
if (import.meta.client === true) {
import('flowbite').then((flowbite) => {
callback(flowbite)
})
}
}
# /pages/foo.vue
<script setup lang="ts">
import { useFlowbite } from '@/composables/useFlowbite'
import { onMounted } from 'vue'
onMounted(() => { useFlowbite(({ initFlowbite }) => { initFlowbite() }) }) ... [REST OF YOUR PAGE]
Describe the bug
I've created a Nuxt.js + Tailwind app according to the documentation here https://flowbite.com/docs/getting-started/nuxt-js/. When running the project locally using
yarn dev
I get the following error.It appears this is from the following line of code
import { initFlowbite } from "flowbite";
.The HTML code
app.vue
contains the Flowbite sidebar https://flowbite.com/docs/components/sidebar/When running this in production using
yarn build && node .output/server/index.mjs
the 500 error does not appear.To Reproduce Steps to reproduce the behavior:
app.vue
file and add the Sidebar vue/html codeyarn dev
500 error occurs
yarn build && node .output/server/index.mjs
the error does not occur.Expected behavior
No 500 error should occur
Screenshots No screen shots.
Desktop (please complete the following information):