Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: r is not a function - next.js

I am trying to use a const from a context in my server side, inside /api. But when I use this, my backend console returns:

TypeError: r is not a function

and

SyntaxError: Unexpected end of JSON input

in the request that, without the context, works perfectly.

I also checked the variable before using it and it is returning the string it should. How to solve this?

'use client'
import { calendarInsertContext } from './calendarInsertContext'

export async function GET(req) {
  const { sdr } = useContext(calendarInsertContext)
  console.log('sdr backend: ', sdr)
like image 680
Maria Eduarda Avatar asked Aug 02 '26 06:08

Maria Eduarda


2 Answers

I have got the same error, apparently i had used 'use client' in my route.ts file which was not required.

it got resolved. it seems that vs-code will not throw any error indicator in file whether we use 'use client' in a file or not.

like image 125
Harish S Chauhan Avatar answered Aug 04 '26 19:08

Harish S Chauhan


If you're using 'next-auth' latest(beta) version it's happen, so downgrade 'next-auth' with stable version it would be resolved.

For more info - Follow this issue

like image 33
Yeasin Arafat Avatar answered Aug 04 '26 19:08

Yeasin Arafat