-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Description
Environment
System:
OS: macOS 15.5
CPU: (11) arm64 Apple M3 Pro
Memory: 70.38 MB / 18.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 24.1.0 - ~/.nvm/versions/node/v24.1.0/bin/node
Yarn: 1.22.19 - ~/.yarn/bin/yarn
npm: 11.3.0 - ~/.nvm/versions/node/v24.1.0/bin/npm
pnpm: 10.12.4 - ~/Library/pnpm/pnpm
Watchman: 2024.12.02.00 - /usr/local/bin/watchman
Browsers:
Chrome: 138.0.7204.168
Edge: 138.0.3351.95
Safari: 18.5
npmPackages:
@auth/core: catalog:next-auth5 => 0.40.0
next: catalog:next15 => 15.4.3
next-auth: catalog:next-auth5 => 5.0.0-beta.29
react: catalog:react19 => 19.1.0
Reproduction URL
https://github.com/craigmcc/craigmcc-turborepo
Describe the issue
The fix committed for #11551 included a change to packages/next-auth/src/lib/env.ts that changed the first line from:
import { NextRequest } from "next/server.js"
to:
/ @ts-expect-error Next.js does not yet correctly use the
package.json#exportsfield import { NextRequest } from "next/server"
This relies, of course, on your environment correctly recognizing that "next/server" imports should actually go to the "server.js" file in the distribution.
For me, this works correctly when I build and run my application, but causes tests to fail (using either Jest or Vitest) trying to load this module. It's the same message that was included in several comments on the #11551 issue.
I have been unable to find any configuration adjustments I can make to my test setups that will make this work.
How to reproduce
Create a NextJS application that uses next-auth. Write a test that imports things. In my case, the folowing was sufficient to cause the problem:
import { signIn, signOut } from "@/auth";
Run the app (either build -> start or dev), and observe that the app works.
Write a test for this app, and observe that trying to run the test fails because of this import.
Expected behavior
Should be able to configure test environments so that they execute the next-auth code appropriately.