nextjs-auth0: Testing helper generateSessionCookie error: subpath './testing' is not defined by "exports"
Checklist
- The issue can be reproduced in the nextjs-auth0 sample app (or N/A).
- I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
- 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: https://github.com/auth0/nextjs-auth0/issues/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
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 31 (15 by maintainers)
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 https://github.com/auth0/nextjs-auth0/issues/1945#issuecomment-2895438150 aligns very closely to the PR I opened to fix this initially: https://github.com/auth0/nextjs-auth0/pull/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.Thanks, I have re-introduced the same changes in https://github.com/auth0/nextjs-auth0/pull/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.
I assume it will be merged tomorrow, and released as part of the next release, yes.
I was able to reproduce the
ERR_REQUIRE_ESMerror you are getting, that seems to be caused by an issue with the version of node you are using.I was using
v20.19.0andv22.13.1and it worked for me, any chance you can confirm you are seeing the same with those versions?This doesn’t mean our SDK is only usable with those versions, but it does mean our SDK is only usable in those versions of Node.js when you want to use
require()to load our SDK because that relies on the support from Node.js itself to require ESM files.In the reproduction you shared, so our own sample app, this is only the cypress file. Which you can also migrate to a
.mjsfile, and then the Node.js version restriction shouldn’t apply.Using a direct import appears to result in a similar error