question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

feat: NextJS EdgeRuntime support

See original GitHub issue

Describe the feature you’d like to request

Since https://github.com/vercel/next.js/pull/39462 applied on NextJS 12.3.*'s EdgeRuntime, an internal server error occurs like below statement

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
warn  - You have enabled experimental feature (runtime) in next.config.js.
warn  - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.

warn  - You are using the experimental Edge Runtime with `experimental.runtime`.
event - compiled client and server successfully in 1406 ms (232 modules)
wait  - compiling / (client and server)...
event - compiled client and server successfully in 860 ms (385 modules)
[Error: A Node.js API is used (setImmediate) which is not supported in the Edge Runtime.
Learn more: https://nextjs.org/docs/api-reference/edge-runtime]
[Error: A Node.js API is used (setImmediate) which is not supported in the Edge Runtime.
Learn more: https://nextjs.org/docs/api-reference/edge-runtime]
wait  - compiling /api/trpc/[trpc] (client and server)...
wait  - compiling /_error (client and server)...
event - compiled client and server successfully in 318 ms (451 modules)
error - (middleware)/node_modules/.pnpm/@trpc+server@10.0.0-proxy-alpha.74/node_modules/@trpc/server/dist/adapters/next.mjs (11:0) @ getPath
error - Cannot read properties of undefined (reading 'trpc')
null
 [TRPCClientError: Unexpected token < in JSON at position 0] {
  meta: undefined,
  shape: undefined,
  data: undefined,
  name: 'TRPCClientError'
}

To Reproduce Error

  1. Clone or run npx create-next-app --example https://github.com/trpc/trpc --example-path examples/next-minimal-starter trpc-minimal-starter
  2. Enable EdgeRuntime with create next.config.js
module.exports = {
    experimental: {
        runtime: "experimental-edge",
      },
}
  1. Run next dev

Describe the solution you’d like to see

TRPC can run well on NextJS EdgeRuntime. Maybe add some polyfill of setImmediate like https://github.com/YuzuJS/setImmediate/blob/master/setImmediate.js

Desribe alternate solutions

Additional information

https://github.com/vercel/next.js/issues/40457

👨‍👧‍👦 Contributing

  • 🙋‍♂️ Yes, I’d be down to file a PR implementing this feature!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
sachinrajacommented, Sep 13, 2022

I tested it and it worked, try clearing .next.

1reaction
sachinrajacommented, Sep 14, 2022

You can’t pass a response object because tRPC needs to set the body of the response. You can set the response headers using the response returned from fetchRequestHandler.

And most NextJS 3rd party modules need to consume NextResponse as argument like https://github.com/vvo/iron-session.

You can also use the Response returned from fetchRequestHandler for this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Edge Runtime - Next.js
The Next.js Edge Runtime is based on standard Web APIs. Learn more about the supported APIs available.
Read more >
And here's another one: the Next.js Edge Runtime becomes ...
js Edge Runtime becomes the fourth full-stack framework supported by Cloudflare Pages. 10/24/2022. October 24, 2022 2:00PM. Greg Brimble.
Read more >
RFC: Switchable Next.js Runtime · Discussion #34179 - GitHub
A runtime option in next.config.js , which can be either nodejs or edge ... This ensures the best ecosystem interoperability and support for...
Read more >
Learn Protected Route Handler – Build a Fullstack App from ...
Build a Fullstack App from Scratch (feat Next.js) Protected Route Handler ... using middleware, and discussing protecting pages utilizing edge functions.
Read more >
Gateways for downstream devices - Azure IoT Edge
Offline support - The gateway device stores messages and twin updates that cannot be delivered to IoT Hub. Transparent gateways. In the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found