Closed
Description
Checklist
- The issue can be reproduced in the nextjs-auth0 sample app (or N/A).I have looked into the API documentation and have not found a suitable solution or answer.I have searched the issues and have not found a suitable solution or answer.I have searched the Auth0 Community forums and have not found a suitable solution or answer.I agree to the terms within the Auth0 Code of Conduct.
Description
We are using PlayWrite and need to generate a session by generateSessionCookie
, this function can be imported in other files but not in testing files, I got this error:
Error: Package subpath './testing' is not defined by "exports" in /Users/......./node_modules/@auth0/nextjs-auth0/package.json
Some other people also face same error: #1857
Reproduction
Follow this example https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#generatesessioncookie in testing file
Additional context
No response
nextjs-auth0 version
4.0.2
Next.js version
15.1.6
Node.js version
22.13.0
Activity
tusharpandey13 commentedon Mar 7, 2025
Thank you for reporting this issue. This is a bug in our exports configuration - the testing utilities aren't properly exposed in the package.json. We'll fix this in our next release.
The fix adds the proper exports configuration:
As a temporary workaround, you can use a direct import:
Please let us know if this solution works for your setup!
brycenrogers commentedon Mar 7, 2025
Using a direct import appears to result in a similar error
stevechan-medi commentedon Mar 18, 2025
Same error
stevechan-medi commentedon Mar 18, 2025
Hey @tusharpandey13 the temp solution not working as well, got error
Error: Package subpath './dist/testing' is not defined by "exports"
And v4.1.0 still have original error
stevechanvii commentedon Mar 26, 2025
Just work around and found a temp solution testing by PlayWright:
Go to node_modules/@auth0>nextjs-auth0/package.json
Add following to "exports":
Go to node_modules/@auth0>nextjs-auth0/dist/testing/generate-session-cookies.js
replace
to
Then patch-package, a temporary solution and still waiting Auth0 find the root issue.
RichWK commentedon Mar 28, 2025
Hi @tusharpandey13, do you have an update for us on this
generateSessionCookie
issue? You mentioned on March 7th that:...but as of
v4.2.1
(released on March 24th) I'm still able to reproduce the issue. The workaround you provided doesn't seem to work.This is blocking us from migrating to
4.x
, as we cannot proceed without a functioning test suite.frederikprijck commentedon Mar 31, 2025
Sorry for the radio silence here, any chance anyone can share a reproduction?
I tried this in my sample application:
And the following is output:
If anyone can share a minimal reproduction, we can look in addressing this.
RichWK commentedon Apr 1, 2025
Thanks @frederikprijck, here's a minimal reproduction of the
generateSessionCookie
issue:You can trigger the error by running
npm run cypress:open
within theSample-01
directory:Full stack trace:
frederikprijck commentedon Apr 2, 2025
Thanks for sharing that, I was able to get the reproduction working with the following steps:
"type": "module"
to Sample-01/package.json"type": "module"
to the SDK's package.json (you can do this in node_modules, to test. But we may need to patch this).mjs
.Doing that, allows me to no longer have the error in question. Can you confirm this would help you as well before we look into this any further?
RichWK commentedon Apr 2, 2025
@frederikprijck I don't think that will help us as we're not in a position to transition our package to ESM at the moment.
frederikprijck commentedon Apr 2, 2025
v4 of our SDK only ships an ESM bundle, and cypress seems to not like that, as far as I understand it needs that configuration to make it work with any ESM only package.
The fact that this is only a cypress problem, makes me believe that your application is already using ESM ? But I may be missing something.
frederikprijck commentedon Apr 2, 2025
We detected a potential issue with the way we publish our SDK, will circle back ASAP with a fix.
10 remaining items
RichWK commentedon Apr 11, 2025
@frederikprijck Thanks for letting us know — do you have plans for a new approach to resolve?
ChabWay commentedon May 7, 2025
Hello @frederikprijck ,
Any update on this one ?
tomer-dev commentedon May 20, 2025
👀
tomer-dev commentedon May 20, 2025
the exports part in
package.json
was enough to get it fixed for me. @stevechanviiAlso please note that 4.4.1 works, 4.5.1 doesn't.
miriarte33 commentedon Jun 15, 2025
Still broken on 4.6.1, any update on this?
frederikprijck commentedon Jun 16, 2025
Apologies, I must have missed the pings.
We have been prioritizing a few other issues, but will take another look into this.
In essense, I think the #1945 (comment) aligns very closely to the PR I opened to fix this initially: #2028
However, doing that breaks the ability to use
getSession()
without passing request in middleware, which we want to avoid and is what we need to figure out, hence why we had to revert the fix, apologies.frederikprijck commentedon Jun 16, 2025
Can anyone confirm that the issue is non-existent in v.4.4.1 before we bring back change (as we reverted it in 4.4.2)?
Thanks
tomer-dev commentedon Jun 16, 2025
@frederikprijck yes, for me it worked in 4.4.1.
frederikprijck commentedon Jun 16, 2025
Thanks, I have re-introduced the same changes in #2171, and called-out the reason why it was reverted in the first place, and why we believe we want to bring back the change as-is.
miriarte33 commentedon Jun 17, 2025
@frederikprijck Any update on when this might be merged? My team is relying on this fix. Really appreciate it
frederikprijck commentedon Jun 18, 2025
The goal is to merge it today, release it at the end of this week.