Skip to content

Testing helper generateSessionCookie error: subpath './testing' is not defined by "exports" #1945

Closed
@stevechanvii

Description

@stevechanvii

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: #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

tusharpandey13 commented on Mar 7, 2025

@tusharpandey13
Contributor

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:

"exports": {
  "./testing": {
    "types": "./dist/testing/index.d.ts",
    "default": "./dist/testing/index.js"
  },
  // other existing exports
}

As a temporary workaround, you can use a direct import:

import { generateSessionCookie } from '@auth0/nextjs-auth0/dist/testing';

Please let us know if this solution works for your setup!

brycenrogers

brycenrogers commented on Mar 7, 2025

@brycenrogers

Using a direct import appears to result in a similar error

Error: Package subpath './dist/testing' is not defined by "exports"
stevechan-medi

stevechan-medi commented on Mar 18, 2025

@stevechan-medi

Using a direct import appears to result in a similar error

Error: Package subpath './dist/testing' is not defined by "exports"

Same error

stevechan-medi

stevechan-medi commented on Mar 18, 2025

@stevechan-medi

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

stevechanvii commented on Mar 26, 2025

@stevechanvii
Author

Just work around and found a temp solution testing by PlayWright:

Go to node_modules/@auth0>nextjs-auth0/package.json
Add following to "exports":

"./testing/generate-session-cookie": {
      "import": "./dist/testing/generate-session-cookie.js",
      "types": "./dist/testing/generate-session-cookie.d.ts",
      "default": "./dist/testing/generate-session-cookie.js"
    }

Go to node_modules/@auth0>nextjs-auth0/dist/testing/generate-session-cookies.js
replace

import { encrypt } from "../server/cookies";

to

import { encrypt } from "../server/cookies.js";

Then patch-package, a temporary solution and still waiting Auth0 find the root issue.

RichWK

RichWK commented on Mar 28, 2025

@RichWK

Hi @tusharpandey13, do you have an update for us on this generateSessionCookie issue? You mentioned on March 7th that:

We'll fix this in our next release

...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

frederikprijck commented on Mar 31, 2025

@frederikprijck
Member

Sorry for the radio silence here, any chance anyone can share a reproduction?

I tried this in my sample application:

import { generateSessionCookie } from "@auth0/nextjs-auth0/testing";

console.log('Output:');
console.log(generateSessionCookie);

And the following is output:

Output:
[Function: generateSessionCookie]

If anyone can share a minimal reproduction, we can look in addressing this.

RichWK

RichWK commented on Apr 1, 2025

@RichWK

Thanks @frederikprijck, here's a minimal reproduction of the generateSessionCookie issue:

You can trigger the error by running npm run cypress:open within the Sample-01 directory:

Image

Full stack trace:

Error: Package subpath './dist/testing' is not defined by "exports" in /Users/redacted/Documents/GitHub/auth0-nextjs-samples/Sample-01/node_modules/@auth0/nextjs-auth0/package.json
    at exportsNotFound (node:internal/modules/esm/resolve:322:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:670:9)
    at resolveExports (node:internal/modules/cjs/loader:634:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:724:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1211:27)
    at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (/Users/redacted/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/node_modules/@cspotcode/source-map-support/source-map-support.js:811:30)
    at Function.Module._load (node:internal/modules/cjs/loader:1051:27)
    at Module.require (node:internal/modules/cjs/loader:1311:19)
    at require (node:internal/modules/helpers:179:18)
    at Object. (/Users/redacted/Documents/GitHub/auth0-nextjs-samples/Sample-01/cypress.config.js:2:35)
    at Module._compile (node:internal/modules/cjs/loader:1469:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
    at Object.require.extensions. [as .js] (/Users/redacted/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/node_modules/ts-node/dist/index.js:851:20)
    at Module.load (node:internal/modules/cjs/loader:1288:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1104:12)
    at Module.require (node:internal/modules/cjs/loader:1311:19)
    at require (node:internal/modules/helpers:179:18)
    at loadFile (/Users/redacted/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_require_async_child.js:89:14)
    at EventEmitter. (/Users/redacted/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_require_async_child.js:116:38)
    at EventEmitter.emit (node:events:518:28)
    at EventEmitter.emit (node:domain:489:12)
    at process. (/Users/redacted/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/util.js:33:22)
frederikprijck

frederikprijck commented on Apr 2, 2025

@frederikprijck
Member

Thanks for sharing that, I was able to get the reproduction working with the following steps:

  • Update cypress to 14.2.1
  • Add "type": "module" to Sample-01/package.json
  • Add "type": "module" to the SDK's package.json (you can do this in node_modules, to test. But we may need to patch this)
  • Migrate the crypress config to use ESM and rename to .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

RichWK commented on Apr 2, 2025

@RichWK

@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

frederikprijck commented on Apr 2, 2025

@frederikprijck
Member

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

frederikprijck commented on Apr 2, 2025

@frederikprijck
Member

We detected a potential issue with the way we publish our SDK, will circle back ASAP with a fix.

10 remaining items

RichWK

RichWK commented on Apr 11, 2025

@RichWK

@frederikprijck Thanks for letting us know — do you have plans for a new approach to resolve?

ChabWay

ChabWay commented on May 7, 2025

@ChabWay

Hello @frederikprijck ,
Any update on this one ?

tomer-dev

tomer-dev commented on May 20, 2025

@tomer-dev

👀

tomer-dev

tomer-dev commented on May 20, 2025

@tomer-dev

Just work around and found a temp solution testing by PlayWright:

Go to node_modules/@auth0>nextjs-auth0/package.json Add following to "exports":

"./testing/generate-session-cookie": {
      "import": "./dist/testing/generate-session-cookie.js",
      "types": "./dist/testing/generate-session-cookie.d.ts",
      "default": "./dist/testing/generate-session-cookie.js"
    }

Go to node_modules/@auth0>nextjs-auth0/dist/testing/generate-session-cookies.js replace

import { encrypt } from "../server/cookies";

to

import { encrypt } from "../server/cookies.js";

Then patch-package, a temporary solution and still waiting Auth0 find the root issue.

the exports part in package.json was enough to get it fixed for me. @stevechanvii

Also please note that 4.4.1 works, 4.5.1 doesn't.

miriarte33

miriarte33 commented on Jun 15, 2025

@miriarte33

Still broken on 4.6.1, any update on this?

frederikprijck

frederikprijck commented on Jun 16, 2025

@frederikprijck
Member

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

frederikprijck commented on Jun 16, 2025

@frederikprijck
Member

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

tomer-dev commented on Jun 16, 2025

@tomer-dev

@frederikprijck yes, for me it worked in 4.4.1.

Just work around and found a temp solution testing by PlayWright:
Go to node_modules/@auth0>nextjs-auth0/package.json Add following to "exports":

"./testing/generate-session-cookie": {
      "import": "./dist/testing/generate-session-cookie.js",
      "types": "./dist/testing/generate-session-cookie.d.ts",
      "default": "./dist/testing/generate-session-cookie.js"
    }

Go to node_modules/@auth0>nextjs-auth0/dist/testing/generate-session-cookies.js replace

import { encrypt } from "../server/cookies";

to

import { encrypt } from "../server/cookies.js";

Then patch-package, a temporary solution and still waiting Auth0 find the root issue.

the exports part in package.json was enough to get it fixed for me. @stevechanvii

Also please note that 4.4.1 works, 4.5.1 doesn't.

frederikprijck

frederikprijck commented on Jun 16, 2025

@frederikprijck
Member

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

miriarte33 commented on Jun 17, 2025

@miriarte33

@frederikprijck Any update on when this might be merged? My team is relying on this fix. Really appreciate it

frederikprijck

frederikprijck commented on Jun 18, 2025

@frederikprijck
Member

The goal is to merge it today, release it at the end of this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @frederikprijck@brycenrogers@tusharpandey13@RichWK@miriarte33

      Issue actions

        Testing helper generateSessionCookie error: subpath './testing' is not defined by "exports" · Issue #1945 · auth0/nextjs-auth0