feat: NextJS EdgeRuntime support
See original GitHub issueDescribe 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
- Clone or run
npx create-next-app --example https://github.com/trpc/trpc --example-path examples/next-minimal-starter trpc-minimal-starter - Enable EdgeRuntime with create next.config.js
module.exports = {
experimental: {
runtime: "experimental-edge",
},
}
- 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:
- Created a year ago
- Comments:7 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I tested it and it worked, try clearing
.next.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.You can also use the
Responsereturned fromfetchRequestHandlerfor this.