Next.js Discord

Discord Forum

How to add error.tsx into next app folder?

Unanswered
Orinoco Crocodile posted this in #help-forum
Open in Discord
Orinoco CrocodileOP
I read this article https://nextjs.org/docs/app/building-your-application/routing/error-handling. It says that I just need put file error.tsx into folder. I have next hierarchy:
/app/(main)/test
page.tsx
error.tsx

But when I manually throw new Error, I don't see interface from error.tsx, just warning in console
'use client'

import { useEffect } from 'react'

export default function Error({ error, reset }: { error: Error; reset: () => void }) {
    useEffect(() => {
        // Log the error to an error reporting service
        console.log(error)
        console.log('error')
    }, [error])

    return (
        <div>
            <h2>Something went wrong!</h2>
            <button onClick={() => reset()}>Try again</button>
        </div>
    )
}

0 Replies