No "exports" main defined in @auth/mongodb-adapter/package.json
Adapter type
@auth/mongodb-adapter
Environment
Standard Next.js project created with create-next-app.
"dependencies": {
"@auth/mongodb-adapter": "^3.9.0",
"mongodb": "^6.16.0",
"next": "15.3.1",
"next-auth": "^4.24.11",
"react": "^19.0.0",
},
"devDependencies": {
"tsx": "^4.19.3",
}
I'm on Windows, I use Node v22.2.0 locally, and I'm testing on Firefox.
Reproduction URL
https://github.com/Gagafeee/next-auth-ERROR-reproduction-fork
Describe the issue
I try to implement unit tests in my application with node built-in test runner.
I use Next-Auth v4 with MongoDB adapter in Docker container.
I use the tsx module to execute my tests files **.test.ts.
But when I run tests with tsx --test, I get this weird error at the point where I import my MongoDBAdapter:
Error: No "exports" main defined in /node_modules/@auth/mongodb-adapter/package.json.
I don't know much about npm module creation, but the package.json of the mogodb-adapter contains an extra "." object with export declaration:
"exports": {
".": {
"types": "./index.d.ts",
"import": "./index.js"
}
}
And everything seems to work when I change it to (according to tsx documentation basic setup):
"exports": "./index.js"
I wonder if it's a tsx bug or what is this "." object.
Thanks in advance for help !
How to reproduce
- Clone the project from the reproduction URL &
npm install. - Run
npm run dev, the server should start correctly, and you should be able to navigate to the home page and to the login page. - Close server and run
npm run test. → Test should fail with anERR_PACKAGE_PATH_NOT_EXPORTEDerror.
A Resolution try:
4. Go to node_modules/@auth/mongodb-adapter/package.json.
5. Change
"exports": {
".": {
"types": "./index.d.ts",
"import": "./index.js"
}
},
to
"exports": "./index.js",
- Re-Run
npm run test. → Test should pass and print MongoDBAdapter object in the console.
Expected behavior
The package should be exported in a way that tsx can read it, and no error should occur.
I'm getting the same error, any updates?
I had this. Turned out to be in the my schema file:
- import { type AdapterAccount } from "next-auth/adapters";
+ import type { AdapterAccountType } from "next-auth/adapters"
I am also seeing this (^3.9.1), despite no linter errors whatsoever. Updating /node_modules/@auth/mongodb-adapter/package.json with:
"exports": "./index.js",
Does indeed work, and downgrading to ^3.8.0 also seems to work in the meantime (avoids manually updating the package.json)