0

Issue

  • Some queries and mutations now produce Unexpected end of JSON input or Unterminated string in JSON at position errors
  • This started happening after rebuilding with an unrelated update. It works locally, but not on the host.

Stack (Turborepo)

  • api (Next.js v13.4.13)
    • page/api/trpc/[trpc].ts
  • client (Next.js v13.4.13)
    • Connects to api using rewrites in next.config.ts
  • trpc
    • routers
    • ...
  • infra: render.com
  • orm: prisma

Code

// apps/api/pages/api/trpc/[trpc].ts
export default createNextApiHandler({
  router: appRouter,
  createContext: createTRPCContext,
});

// apps/client/next.config.ts
async rewrites() {
    return [
      {
        source: "/api/trpc/:path*",
        destination: `${process.env.NEXT_PUBLIC_API}/api/trpc/:path*`,
      },
    ];
  },

Reponse Sample

// status: 200 GET
[
    {
        "result": {
            "data": {
                "json": [
                    {
                        "items": [
                            {
                                "id": "uuid",
                                "label": "label",
                                "status": "statusA",
                                "history": [
                                    {
                                        "creatorA // => creatorAccount
// status: 200 POST
[
    {
        "result": {
            "data": {
                "json": {
                    "ok": true
                },
                "meta": {
                    "v

What I've tried

  • Directly connecting to the api with ThunderClient, etc.
    • No change => It seems not to be a client-side configuration mistake
  • Setting response headers
    • Fixing Content-Type and Content-Encoding didn't make any difference
  • Fixing versions of npm modules
    • No change

Ensuring all queries/mutations work as before

repomn
  • 1
  • 2

1 Answers1

0

CORS settings were not set and I added, the issue is resolved.

repomn
  • 1
  • 2
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 21 '23 at 16:29