Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Gagafeee opened this issue Apr 22, 2025 · 1 comment
Open

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

Gagafeee opened this issue Apr 22, 2025 · 1 comment
Labels
adapters Changes related to the core code concerning database adapters bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@Gagafeee
Copy link

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.

@Gagafeee Gagafeee added adapters Changes related to the core code concerning database adapters bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Apr 22, 2025
@DeividZavala
Copy link

I'm getting the same error, any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adapters Changes related to the core code concerning database adapters bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

No branches or pull requests

2 participants