Skip to content
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

When middleware.ts is specified, runtime is set to edge instead of node #48638

Open
1 task done
ecumene opened this issue Apr 20, 2023 · 6 comments
Open
1 task done
Labels
bug Issue was opened via the bug report template. Runtime Related to Node.js or Edge Runtime with Next.js.

Comments

@ecumene
Copy link

ecumene commented Apr 20, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.3.0: Mon Jan 30 20:39:35 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T8103
    Binaries:
      Node: 19.8.1
      npm: 9.5.1
      Yarn: 1.22.19
      pnpm: N/A
    Relevant packages:
      next: 13.3.1-canary.16
      eslint-config-next: 13.3.0
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

Middleware / Edge (API routes, runtime)

Link to the code that reproduces this issue

https://github.com/ecumene/next-reproduce-edge-middleware

To Reproduce

  1. Setup a next app and yarn build
  2. Notice the .next project is built for a node runtime (Compatible with SST in my case)
  3. Create a middleware.ts file
  4. Notice the .next project is built for an edge runtime (Incompatible with SST)

Describe the Bug

An edge-runtime-webpack.js file is present in .next when it shouldn't be there.

Expected Behavior

The project should be built for a node runtime.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

SST

@ecumene ecumene added the bug Issue was opened via the bug report template. label Apr 20, 2023
@github-actions github-actions bot added the Runtime Related to Node.js or Edge Runtime with Next.js. label Apr 20, 2023
@Defrosted
Copy link

Defrosted commented Apr 21, 2023

The issues people have in #48302 are probably caused by this as well, as the libraries people use in their middlewares that have the same problem differ.

It's worth mentioning that a part of the issue here is also that the edge-chunks generated by the middleware during a standalone mode build aren't copied over to the standalone directory, causing the server function to outright crash when it attempts to load missing files.

@DuCanhGH
Copy link
Contributor

DuCanhGH commented Apr 22, 2023

@Defrosted

It's worth mentioning that a part of the issue here is also that the edge-chunks generated by the middleware during a standalone mode build aren't copied over to the standalone directory, causing the server function to outright crash when it attempts to load missing files.

I thought I fixed this a few months ago, perhaps something went wrong... Time to check :)

Edit: this is weird, seems that this no longer works... I'm on it :)

Edit 2: ah, it was never fixed for middleware...

@DuCanhGH
Copy link
Contributor

@ecumene middleware.js only supports the Edge runtime (the maintainers wanted to make it lightweight as it is invoked every time a page is visited - even client-side transitions count). So perhaps this is working as intended, though you might want to make a feature request on that :)

@wowczarczyk
Copy link

wowczarczyk commented Apr 24, 2023

@DuCanhGH is this related to: #48723 ?

@DuCanhGH
Copy link
Contributor

@wowczarczyk no, but it is related to Defrosted's comment.

@wowczarczyk
Copy link

wowczarczyk commented Apr 24, 2023

OK, cool, for now I added additional COPY statement in my Dockerfile to mitigate this:

COPY --from=builder --chown=nextjs:nodejs /app/.next/server/edge-chunks ./.next/server/edge-chunks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
Development

No branches or pull requests

4 participants