Skip to content

[BUG] Authjs middleware casues self._ENTRIES[b.name].default is not a function #252

Closed
@mackenly

Description

@mackenly

Describe the bug

When Authjs' middleware is used (see below), the following error is thrown:

[wrangler:err] TypeError: self._ENTRIES[b.name].default is not a function
    at Object.edgeFunctionHandler (file:///mnt/c/MyRepos/temp-auth-js-demo/auth-js-d1-example-test/.open-next/middleware/handler.mjs:7841:79)
    at handleMiddleware (file:///mnt/c/MyRepos/temp-auth-js-demo/auth-js-d1-example-test/.open-next/middleware/handler.mjs:9058:35)
    at async routingHandler (file:///mnt/c/MyRepos/temp-auth-js-demo/auth-js-d1-example-test/.open-next/middleware/handler.mjs:9239:25)
    at null.<anonymous> (async file:///mnt/c/MyRepos/temp-auth-js-demo/auth-js-d1-example-test/.wrangler/tmp/dev-jKZoIg/worker.js:1294:100909)
    at null.<anonymous> (async file:///mnt/c/MyRepos/temp-auth-js-demo/auth-js-d1-example-test/.wrangler/tmp/dev-jKZoIg/worker.js:1294:72131)
    at null.<anonymous> (async file:///mnt/c/MyRepos/temp-auth-js-demo/auth-js-d1-example-test/.wrangler/tmp/dev-jKZoIg/worker.js:859:15291)
    at null.<anonymous> (async file:///mnt/c/MyRepos/temp-auth-js-demo/auth-js-d1-example-test/.wrangler/tmp/dev-jKZoIg/worker.js:1366:52043)
    at async jsonError (file:///mnt/c/MyRepos/temp-auth-js-demo/auth-js-d1-example-test/node_modules/wrangler/templates/middleware/middleware-miniflare3-json-error.ts:22:10)
    at async drainBody (file:///mnt/c/MyRepos/temp-auth-js-demo/auth-js-d1-example-test/node_modules/wrangler/templates/middleware/middleware-ensure-req-body-drained.ts:5:10)
[wrangler:inf] GET / 500 Internal Server Error (1596ms)

Authjs middleware.ts (from here):

export { auth as middleware } from "./app/auth";

If I use an example middleware like this one, everything works as expected. It's only with Authjs that it seems to break.

Steps to reproduce

Here's a repo with the code: https://github.com/mackenly/temp-auth-js-demo
Minimal example with Authjs installed.

Expected behavior

No exceptions to be thrown.

@opennextjs/cloudflare version

0.3.8

Wrangler version

3.101.0

next info output

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP Wed Mar 2 00:30:59 UTC 2022
  Available memory (MB): 15900
  Available CPU cores: 16
Binaries:
  Node: 20.13.1
  npm: 10.5.2
  Yarn: 1.22.19
  pnpm: 9.15.4
Relevant Packages:
  next: 14.2.5 // An outdated version detected (latest is 15.1.4), upgrade is highly recommended!
  eslint-config-next: 14.2.5
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.7.3
Next.js Config:
  output: N/A
 ⚠ An outdated version detected (latest is 15.1.4), upgrade is highly recommended!

Additional context

No response

Metadata

Metadata

Labels

bugSomething isn't workingtriage

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions