Back

cookie import failure nextjs component calling server action

  • 0
  • Databases
  • Tools
  • Web
  • Self Hosted
Suiii
31 Jul, 2024, 15:36
TypeScript
Error: 
  × You're importing a component that needs next/headers. That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/getting-started/
  │ react-essentials#server-components


   ╭─[P:\web-app\lib\appwrite.ts:1:1]
 2 │ import { cookies } from 'next/headers';
TypeScript
 useEffect(() => {
    const fetchData = async () => {
      try {
             const model = await loadEmployees()
             setEmployees(model.documents as Employee[])          
        }        
      } catch (error) {
        log.error("Error fetching data SERVER ACTION:", error);
      }
    }
    fetchData();
   
  }, [])

I read the documentation of nextjs , it should be working fine!

TL;DR
Issue with importing a component requiring 'next/headers' in a Server Component not supported in pages/ directory. Make sure to add 'use server' at the top of appwrite.ts file.
Kenny
31 Jul, 2024, 15:39

did you put 'use server' at the top of your appwrite.ts file?

Suiii
31 Jul, 2024, 15:42

no. if i put , it getting this error

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more