The ReferenceError: React is not defined error when using @auth0/nextjs-auth0/server

Hi everyone!

I’m currently trying to migrate my nextjs app to v4 of @auth0/nextjs-auth0 package. I went through all docs, examples, and I already stuck on the first step when simply using auth0 client instance in middleware. I’m getting React not defined error and could not find any similar topics. I’m importing the Auth0Client class from /server path (which should not use any React imo) and getting the error.

I’m using Pages router and nextjs version is 14.2.32.

Hi @BohdanYavorskyi

Welcome back to the Auth0 Community!

Can you try adding import React from 'react' inside the page component where this error is being thrown?

Kind Regards,
Nik

Sure, it’s the first thing I tried. Nothing helped :slight_smile:

It seems it happens due to some react imports in /server output, idk :frowning:

Besides, could I reach you in some chat about how refresh token flow is really working and how it’s handled in the package?

I see, indeed, most probably it is caused by some react imports or version issues, this can be quite hard to troubleshoot without taking a look at the code itself. I would recommend to open an issue on the SDK’s Github page in order to post the errors received and go through the code to troubleshoot it.

Otherwise, refresh tokens behaviour and handling is explained in the EXAMPLES.MD file of the SDK, you check it out on the Github Documentation here, if you have any further questions regarding the matter, you can post them here or as you have mentioned, feel free to send me a DM if that is more comfortable with you!

Kind Regards,
Nik

1 Like

Hi again!

As far as I can see from the issue you have opened, a bug fix has been opened regarding the error that you are receiving!

If you still experience issues after this is rolled out, I would recommend to continue the discussion on the opened issue!

Kind Regards,
Nik

1 Like