5

I installed tailwind and flowbite to a NextJS project. As I did import "flowbite" in _app.tsx, I get the following error.

ReferenceError: document is not defined
    at Object.366 (D:\shopflo\next-tailwind-typescript-starter\node_modules\flowbite\dist\flowbite.js:35:1)
    at __webpack_require__ (D:\shopflo\next-tailwind-typescript-starter\node_modules\flowbite\dist\flowbite.js:496:41)
    at D:\shopflo\next-tailwind-typescript-starter\node_modules\flowbite\dist\flowbite.js:509:17
    at D:\shopflo\next-tailwind-typescript-starter\node_modules\flowbite\dist\flowbite.js:2631:3
    at Object.<anonymous> (D:\shopflo\next-tailwind-typescript-starter\node_modules\flowbite\dist\flowbite.js:2633:12)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Module.require (internal/modules/cjs/loader.js:961:19)
error - ReferenceError: document is not defined
ReferenceError: document is not defined
    at Object.366 (D:\shopflo\next-tailwind-typescript-starter\node_modules\flowbite\dist\flowbite.js:35:1)
    at __webpack_require__ (D:\shopflo\next-tailwind-typescript-starter\node_modules\flowbite\dist\flowbite.js:496:41)
    at D:\shopflo\next-tailwind-typescript-starter\node_modules\flowbite\dist\flowbite.js:509:17
    at D:\shopflo\next-tailwind-typescript-starter\node_modules\flowbite\dist\flowbite.js:2631:3
    at Object.<anonymous> (D:\shopflo\next-tailwind-typescript-starter\node_modules\flowbite\dist\flowbite.js:2633:12)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Module.require (internal/modules/cjs/loader.js:961:19)

document is not defined gives a clue that javascript is creating problems. Please help with this. In my tsconfig.json allowJS:true is set then why is this creating problems?

3
  • As next.js is server-side-rendered no document or window (browser only) are present. stackoverflow.com/questions/24647839/… Commented Feb 23, 2022 at 13:40
  • I'm facing same issue now. Did you later find your way around it? If yes, how? Commented Mar 3, 2022 at 7:42
  • I used headless-ui instead. Commented Mar 4, 2022 at 5:42

3 Answers 3

2

This work fine for me. Every flowbite component have a init function to make it interactive.

import { initAccordions } from "flowbite";

  useEffect(() => {
    initAccordions();
  });

Sign up to request clarification or add additional context in comments.

Comments

1

from the docs, Flowbite is currently working on a standalone library for compatibility with React frameworks such as NextJS check here

Comments

-1

if you are using remix js just add import 'flowbite' in entry.client.tsx file

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.