Next.js Discord

Discord Forum

TypeError: e is undefined

Answered
aprilia posted this in #help-forum
Open in Discord
Avatar
How to debug prod errors when it happens only in vercel and not in local machine
Image

69 Replies

Avatar
@DeFc0n
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'

export function middleware(request: NextRequest) {
    const requestHeaders = new Headers(request.headers)
    requestHeaders.set('x-pathname', request.nextUrl.pathname)
    const response = NextResponse.next({
        request: {
            // New request headers
            headers: requestHeaders,
        },
    })
    return response
}

export const config = {
    matcher: [
        /*
         * Match all request paths except for the ones starting with:
         * - api (API routes)
         * - _next/static (static files)
         * - _next/image (image optimization files)
         * - favicon.ico (favicon file)
         */
        '/((?!api|_next/static|_next/image|favicon.ico).*)',
    ],
}

this is the most recent change i have made
Avatar
okay show me the console in vs code
Avatar
Image
Avatar
keep the console open and refresh
Avatar
I did refresh but i dont see any new logs in the terminal
Avatar
in the browser
there should be a bunch of react errors
when you refresh
Avatar
Image
Avatar
its fixed?
Avatar
no
like i said in local machine i dont see any error
only after deploying to vercel i see the error and the error message aint helpful at all
Avatar
in local machine it works but in vercel it shows the error?
Avatar
yes
Avatar
forget local machine, show me vercel logs
Avatar
this is the most recent change
const pathname = headersList.get("next-url")

from this ^ i have added the middleware and changed it to
const pathname = headersList.get("x-pathname")
Image
Avatar
dont see anythink wrong in there
are there other logs, other then api logs
Avatar
no
Avatar
try rebuild
Avatar
is there any way to get full error message in vercel ?
Avatar
never used vercel for hosting so i cant really tell you,
try to rebuild the project
Avatar
yeah rebuilding
Avatar
most likely wont fix it ill do some digging
Avatar
https://github.com/coding-club-gct/blogs
repo if you would like to see 🙂
rebuild completed, verfied it in private window still the same issue
damn :(
i know its frosturating but dont give up, eventually you will fix it
Avatar
yeah, i have to do some really annoying if statements and deploy each time
Avatar
in your local machine, try this
npm run build npm run start
Avatar
i think i can do this, but its frustrating :(
Avatar
and see if the error happens there
as this error happens in production, not development, you run npm run build to build the production files, then npm run start
Avatar
yeah like i said production mode in local machine works fine
no error
Avatar
thats odd
Avatar
TypeError: Cannot destructure property 'auth' of 'e' as it is undefined.
i got this error
Avatar
check where you have perfomed .auth
Avatar
this error happens when trayng to access a null object
in your case e is undefined
Avatar
i navigate to how to blog
Avatar
oh
Avatar
btw hello ray, hope you had a nice day
Avatar
 const { name, blog, html_url, email } = await getProfileFromUsername(author.login)
    const { name: committerName } = await getProfileFromUsername(committer.login)

i think the error come from here
Avatar
yeah i can see the error message in chrome as well
damn firefox and chrome giving different error messages
:mind_blow_astonished:
Avatar
you too 😀
Avatar
my day was mid, could for the love of me, not get data revalidation to work
Avatar
revalidation something is a little bit tricky for now 😆
Avatar
then i tried router.reload
guess what it didnt work
if i had to track the time i spend, 99% is bug fixing
Avatar
apparently something is getting messed up with the Link component
Answer
Avatar
i have replaced all the Link with <></> and now its working
Avatar
what were you using link for?
Avatar
i get few urls from github api and print it in the page
with link tag
Avatar
glad to be of help, even if it was 1%, mark this as solved
Avatar
yes, thank you as well
Avatar
you're welcome
you can also close the post,