#Unable to use tw-elements in Next.js project

3 messages · Page 1 of 1 (latest)

candid shard
#

Hello!
I am looking to use tw-elements to facilitate some awesome UI feedback in my Next.js project.
For now, I am following https://tailwind-elements.com/docs/standard/integrations/next-integration/

However on step 5 in the tutorial, I get this error:

▲ ReferenceError: document is not defined
▲    at 7086 (C:\Users\user\Documents\projects\my-first-nextjs-project\.next\server\pages\components\Header.js:7:19786)

My component code is as follow:

import Logo from "./Logo";
import HeaderTabLink from "./header/HeaderTabLink";

import { useEffect } from "react";
import { Offcanvas, initTE } from "tw-elements";

declare type HeaderTabType = "home" | "features" | "contact"

declare type HeaderProps = {
  tab: HeaderTabType;
}

export default function Header(props: HeaderProps) {
  useEffect(() => {
    initTE({ Offcanvas });
  }, []);

  return (<>... content here ...</>)

and my tailwind.config.js file is as follow:

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    './pages/**/*.{js,ts,jsx,tsx}',
    './components/**/*.{js,ts,jsx,tsx}',
    './app/**/*.{js,ts,jsx,tsx}',
  ],
  theme: {
    extend: {
      backgroundImage: {
        'gradient-radial': 'radial-gradient(var(--tw-gradient-stops))',
        'gradient-conic':
          'conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))',
      },
    },
  },
  plugins: [require('tw-elements/dist/plugin.cjs')],
}

Why is the Vercel Next.js build process failing? What do I need to do to fix it? 😄

Tailwind Elements

This article shows you how to integrate Next application with Tailwind Elements. Free download, AGPL license.

iron solar
#

u need to put use client

#

i'm assuming u're using app router