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

_error is treated as a serverless function even though the edge runtime is specified (in Pages) #48490

Open
1 task done
dario-piotrowicz opened this issue Apr 17, 2023 · 4 comments · May be fixed by vercel/vercel#10726
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

@dario-piotrowicz
Copy link

dario-piotrowicz commented Apr 17, 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.4.0: Mon Mar  6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000
    Binaries:
      Node: 16.16.0
      npm: 8.11.0
      Yarn: 1.22.15
      pnpm: 6.11.0
    Relevant packages:
      next: 13.3.1-canary.9
      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/dario-piotrowicz/nextjs-_error-edge-demo

To Reproduce

Run npm run build and view the .next/server/middleware-manifest.json file

Describe the Bug

the _error is not present in the middleware manifest thus it is being treated as a serverless function instead of an edge route, basically ignoring the user provided config

Expected Behavior

_error should be present as a field of the functions object inside the middleware manifest thus it will be deployed as an edge route as requested by the user provided config

Additional Information

  • Seems like this only happens with the Pages routing, App routing seems to be fine

  • By looking at the Vercel cli source code (specifically here) it looks to me like the way of discerning if a function is a serverless one or an edge one is to check their presence in the middleware manifest, so I based the details above on this assumption

  • Regardless on the middleware manifest I noticed the issue when running vercel build since, as you can see from the following screenshot generates a node serverless function instead of an edge one:
    Screenshot 2023-04-17 at 14 34 21

@dario-piotrowicz dario-piotrowicz added the bug Issue was opened via the bug report template. label Apr 17, 2023
@github-actions github-actions bot added the Runtime Related to Node.js or Edge Runtime with Next.js. label Apr 17, 2023
@dario-piotrowicz dario-piotrowicz changed the title _error is treated as a serverless function even thought the edge runtime is specified _error is treated as a serverless function even though the edge runtime is specified Apr 17, 2023
@dario-piotrowicz dario-piotrowicz changed the title _error is treated as a serverless function even though the edge runtime is specified _error is treated as a serverless function even though the edge runtime is specified (in the Pages directory, not App) Jun 15, 2023
@dario-piotrowicz dario-piotrowicz changed the title _error is treated as a serverless function even though the edge runtime is specified (in the Pages directory, not App) _error is treated as a serverless function even though the edge runtime is specified (in Pages) Jun 15, 2023
@matiasironyard
Copy link

Any progress on this issue? We are facing a similar issue. Here is our error code:

"use client";

import { useEffect } from "react";

export const runtime = "edge";

export default function Error({
  error,
  reset,
}: {
  error: Error;
  reset: () => void;
}) {
  useEffect(() => {
    // Log the error to an error reporting service
    // eslint-disable-next-line no-console
    console.error(error);
  }, [error]);

  return (
    <div>
      <h2>Something went wrong!</h2>
      <button
        type="button"
        onClick={
          // Attempt to recover by trying to re-render the segment
          () => reset()
        }
      >
        Try again
      </button>
    </div>
  );
}

Build error:

13:41:08.376 ⚡️ Completed yarn vercel build.
13:41:11.547  
13:41:11.548 ⚡️ ERROR: Failed to produce a Cloudflare Pages build from the project.
13:41:11.548 ⚡️
13:41:11.548 ⚡️ The following routes were not configured to run with the Edge Runtime:
13:41:11.548 ⚡️ - /_error
13:41:11.548 ⚡️
13:41:11.548 ⚡️ Please make sure that all your non-static routes export the following edge runtime route segment config:
13:41:11.549 ⚡️ export const runtime = 'edge';
13:41:11.549 ⚡️
13:41:11.549 ⚡️ You can read more about the Edge Runtime on the Next.js documentation:
13:41:11.549 ⚡️ https://nextjs.org/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes

@simpson
Copy link

simpson commented Sep 2, 2023

Any updates?

@simpson
Copy link

simpson commented Sep 14, 2023

Any chance you will review this?

@sylee999
Copy link

sylee999 commented Sep 25, 2023

I have the same issue, but my app is using app routing.

When I used previous nextjs version 13.4.19, it worked well.
As I updated the newest one, I had the same error.
It seems like this bug was happened from 13.5.X.

So, you'd better use previous version like 13.4.19 while they are fixing it.

I just hope this problem be fixed soon.

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

Successfully merging a pull request may close this issue.

4 participants