trpc: DX: using `client` as the route name causes an error

Provide environment information

System:
    OS: macOS 13.1
    CPU: (8) x64 Apple M1
    Memory: 18.31 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.12.1 - ~/.nvm/versions/node/v18.12.1/bin/node
    Yarn: 1.22.10 - /opt/homebrew/bin/yarn
    npm: 8.19.2 - ~/.nvm/versions/node/v18.12.1/bin/npm
    Watchman: 2022.10.03.00 - /opt/homebrew/bin/watchman
  Browsers:
    Brave Browser: 109.1.47.171
    Chrome: 109.0.5414.119
    Safari: 16.2
  npmPackages:
    @tanstack/react-query: ^4.20.4 => 4.24.4 
    @trpc/client: ^10.7.0 => 10.9.1 
    @trpc/next: ^10.7.0 => 10.9.1 
    @trpc/react-query: ^10.7.0 => 10.9.1 
    @trpc/server: ^10.7.0 => 10.9.1 
    next: ^13.1.1 => 13.1.6 
    react: ^18.2.0 => 18.2.0 
    typescript: ^4.9.4 => 4.9.5 

Describe the bug

I’ve created a route and named it client but I get this error when trying to use trpc.useContext()

client collides with a built-in method, you should rename this router or procedure on your backend

I could fix the issue by renaming it to clientRoute and the problem was solved

Link to reproduction

https://stackblitz.com/github/trpc/examples-next-minimal-starter

To reproduce

Create a route and name it client, This should trigger an error as shown in the video below:

https://user-images.githubusercontent.com/56588770/216343859-4bd76863-845e-45bd-a664-0911b4ed0054.mov

Additional information

No response

👨‍👧‍👦 Contributing

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

TRP-54

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 4
  • Comments: 21 (5 by maintainers)

Most upvoted comments

as it turned out, my solution above was not solving the situation at all. After killing a lot of time doing research, I finally understand that all the root cause of problem were references in tsconfig.json file

https://github.com/kuubson/react-vite-trpc this repository helped me

tldr; add the following inside the root object of tsconfig.json in the project where you want to import AppRouter:

{
    "compilerOptions": {...},
    "references": [
          {
              "path": "../server" // path to the project's tsconfig.json which has AppRouter type we want to import
          }
    ]
}

I’m also getting this error randomly on my build server:

app:build: Failed to compile.
--
app:build:
app:build: ./src/pages/_app.tsx:87:21
app:build: Type error: Property 'withTRPC' does not exist on type '"The property 'useContext' in your router collides with a built-in method, rename this router or procedure on your backend." \| "The property 'withTRPC' in your router collides with a built-in method, rename this router or procedure on your backend." \| "The property 'useQueries' in your router collides with a built-i...'.
app:build:   Property 'withTRPC' does not exist on type '"The property 'useContext' in your router collides with a built-in method, rename this router or procedure on your backend."'.
app:build:
app:build:   86 \|
app:build: > 87 \| export default trpc.withTRPC(App);
app:build:      \|                     ^
app:build:   88 \|
app:build:  ELIFECYCLE  Command failed with exit code 1.
app:build: ERROR: command finished with error: command (/vercel/path0/packages/app) pnpm run build exited (1)
command (/vercel/path0/packages/app) pnpm run build exited (1)
 
Tasks:    1 successful, 2 total
Cached:    1 cached, 2 total
Time:    19.473s
Summary:    /vercel/path0/.turbo/runs/2OL0f9u0IvChFcvtJWdcgOBVjIw.json
 
ERROR  run failed: command  exited (1)
ELIFECYCLE  Command failed with exit code 1.
Error: Command "pnpm build:app" exited with 1
Deployment completed
BUILD_UTILS_SPAWN_1: Command "pnpm build:app" exited with 1

Does anyone have a reproduction where this error should not be showing up (you do not have actually have a procedure named something that collides with a built-in method)?

Rename it to something else.

Hey, what exactly should I rename? I fixed the error with updating tRPC

I had the same issue and for me the fix was to delete the node_modules and the package-lock.json from the root folder of my repo and the two folders for my app and server. Then ran npm install only in the root. That made it so I only have a node_modules and package-lock.json in the root folder and no longer in the two subfolders and made the error go away.

explicitly setting type helped me to resolve this annoying situation

instead of

export const trpc = createTRPCReact<AppRouter>()

i wrote

export const trpc: CreateTRPCReact<AppRouter, unknown, null> = createTRPCReact<AppRouter>()

I think this happened after upgrading as a result of #3693.

I think it’s worth investigating a bit more if there are non-breaking workarounds we can do to prevent this as I think it’s really bad DX