next-auth icon indicating copy to clipboard operation
next-auth copied to clipboard

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

Open Gagafeee opened this issue 1 year ago • 3 comments

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 avatar Apr 22 '25 19:04 Gagafeee

I'm getting the same error, any updates?

DeividZavala avatar May 03 '25 19:05 DeividZavala

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"

matburnham avatar May 25 '25 17:05 matburnham

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)

mdatz avatar Jun 04 '25 04:06 mdatz