nextauthjs / nextauthjs/next-auth

No "exports" main defined in @auth/mongodb-adapter/package.json

Open
#12,895 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

adapters bug triage
Dominant language
TypeScript
Stars
28.4k
Forks
4k
PR merge metrics
No merged PRs in 30d

Description

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
  1. Clone the project from the reproduction URL & npm install.
  2. 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.
  3. Close server and run npm run test.
    → Test should fail with an ERR_PACKAGE_PATH_NOT_EXPORTED error.

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",
  1. 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with @auth/mongodb-adapter/package.json and its exports entry, then reproduce the failure in the linked project with npm run test via tsx --test. Done means the MongoDBAdapter import resolves without ERR_PACKAGE_PATH_NOT_EXPORTED while the existing development flow still works.

Written by the indexing model from the issue text.

Assessment

Tech stack
mongodb, nextjs, nodejs, typescript
Domain
authentication, backend, databases
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.