Skip to content

[BUG]: Next.js 15 + middleware causes __import_unsupported error #177

@dario-piotrowicz

Description

@dario-piotrowicz

Describe the bug

If I have an Next.js app that is on Next.js 15 and has a middleware, the adapter can build the application but at runtime the application throws a __import_unsupported error:
Screenshot 2024-12-15 at 19 17 56

Steps to reproduce

  • Create a new Next.js 15 application
  • Install the adapter (the experimental release)
  • add a middleware file
  • build and preview the application
  • navigate to the application's url to see the error

Minimal reproduction: https://github.com/dario-piotrowicz/open-next-15-middleware-experimental-repro

Expected behavior

The application should just work

@opennextjs/cloudflare version

https://pkg.pr.new/@opennextjs/cloudflare@experimental

Node.js version

20

Wrangler version

3

next info output

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.1.0: Thu Oct 10 21:03:15 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 10
Binaries:
  Node: 20.11.0
  npm: 10.2.4
  Yarn: 1.22.19
  pnpm: 9.12.1
Relevant Packages:
  next: 15.1.0 // Latest available version is detected (15.1.0).
  eslint-config-next: 14.2.5
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.7.2
Next.js Config:
  output: N/A

Additional context

#141 implements a simple fix for this

but:

  • the fix should be done properly with AST manipulation
  • we should understand better why this issue gets triggered and if the proposed patch is the appropriate solution

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriage

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions