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
feat: NextJS EdgeRuntime support #2697
Comments
I don't know why the /**
* This is the API-handler of your app that contains all your API routes.
* On a bigger app, you will probably want to split this file up into multiple files.
*/
import { initTRPC } from "@trpc/server";
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
import { NextRequest } from "next/server";
import { z } from "zod";
const t = initTRPC.create();
const appRouter = t.router({
greeting: t.procedure
// This is the input schema of your procedure
// 💡 Tip: Try changing this and see type errors on the client straight away
.input(
z
.object({
name: z.string().nullish(),
})
.nullish()
)
.query(({ input }) => {
// This is what you're returning to your client
return {
text: `hello ${input?.name ?? "world"}`,
// 💡 Tip: Try adding a new property here and see it propagate to the client straight-away
};
}),
// 💡 Tip: Try adding a new procedure here and see if you can use it in the client!
// getUser: t.procedure.query(() => {
// return { id: '1', name: 'bob' };
// }),
});
// export only the type definition of the API
// None of the actual implementation is exposed to the client
export type AppRouter = typeof appRouter;
// export API handler
export default (req: NextRequest) => {
return fetchRequestHandler({
router: appRouter,
req,
endpoint: "/api/trpc",
createContext: () => ({}),
});
}; |
@sachinraja thanks for your reply. But I have tried to add
and still not working.. can you provide complete solution for this case ? |
I tested it and it worked, try clearing |
@sachinraja, I try to rewrite my code based on this solution. But I have found fetchRequestHandler is missing NextResponse argument. We need to set response's headers to allow CORS. And most NextJS 3rd party modules need to consume NextResponse as argument like https://github.com/vvo/iron-session.
Please elaborate how to integrate the modules by using fetchRequestHandler |
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
You can also use the |
Found issue while using Prisma : prisma/prisma#15313 |
This issue has been locked because it had no new activity for 14 days. If you are running into a similar issue, please create a new issue. Thank you. |
Describe the feature you'd like to request
Since vercel/next.js#39462 applied on NextJS 12.3.*'s EdgeRuntime, an internal server error occurs like below statement
To Reproduce Error
npx create-next-app --example https://github.com/trpc/trpc --example-path examples/next-minimal-starter trpc-minimal-starter
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
vercel/next.js#40457
👨👧👦 Contributing
The text was updated successfully, but these errors were encountered: