无法在 netlify 上使用 tRPC 构建我的前端应用程序

问题描述 投票:0回答:1

我正在使用 React Typescript,我按照 tRPC 文档 进行服务器/客户端设置,但我收到此错误。有谁知道为什么部署时会发生这种情况?当我在本地使用它时它工作正常吗?

8:41:46 AM: TS2339: Property 'createClient' does not exist on type '"useContext collides with a built-in method, you should rename this router or procedure on your backend" | "Provider collides with a built-in method, you should rename this router or procedure on your backend" | "createClient collides with a built-in method, you should rename this router or procedure on your backend...'.
8:41:46 AM:   Property 'createClient' does not exist on type '"useContext collides with a built-in method, you should rename this router or procedure on your backend"'.
8:41:46 AM:     42 |   const [queryClient] = useState(() => new QueryClient());
8:41:46 AM:     43 |   const [trpcClient] = useState(() =>
8:41:46 AM:   > 44 |     trpc.createClient({
8:41:46 AM:        |          ^^^^^^^^^^^^
8:41:46 AM:     45 |       links: [
8:41:46 AM:     46 |         httpBatchLink({
8:41:46 AM:     47 |           url: `${process.env.REACT_APP_BACKEND_URL}/trpc`,
8:41:46 AM: ​
8:41:46 AM:   "build.command" failed        

我的应用程序.tsx

export default function App() {
  const [queryClient] = useState(() => new QueryClient());
  const [trpcClient] = useState(() =>
    trpc.createClient({
      links: [
        httpBatchLink({
          url: `${process.env.REACT_APP_BACKEND_URL}/trpc`,
        }),
      ],
    })
  );

  return (
    <trpc.Provider client={trpcClient} queryClient={queryClient}>
      <QueryClientProvider client={queryClient}>    
........... rest of code here



        
reactjs typescript trpc.io
1个回答
0
投票

这是因为您正在从后端导入

trpc
,因为您已经在本地编译后端但在 Netlify/Vercel 上部署时跳过了该步骤。

© www.soinside.com 2019 - 2024. All rights reserved.