H
Hono4mo ago
Henrik

RPC frontend import

Did anyone else also have the problem of building the frontend app when importing the RPC Types from the backend? How did you solve it? I don't know what to do anymore... I always get errors on non-existing imports in the frontend - this is pretty easy to understand because they are imports from the backend app. How can I solve it?
5 Replies
ambergristle
ambergristle4mo ago
sounds like you're using a monorepo, in which case you want to generate a declaration file during transpilation and import the types that way making imports across a monorepo work also typically requires some configuration, e.g., using workspaces, but that depends on your setup hard to say more without having a better sense of your project setup
Henrik
HenrikOP4mo ago
project/
├── apps/
│ ├── web
│ └── server
├── packages/
│ ├── api
│ ├── ui
│ └── ...
└── ...
project/
├── apps/
│ ├── web
│ └── server
├── packages/
│ ├── api
│ ├── ui
│ └── ...
└── ...
This is basically my project structure Inside the api package I export from my server app (AppType for the RPC, etc.) However, when I run in dev mode everything works fine. When building it crashes. Do you need more information @ambergristle ? :) Thanks for helping
ambergristle
ambergristle4mo ago
Why is /api separate from /server? Also, how are you generating types, and building the app?
Henrik
HenrikOP4mo ago
Because I thought that it would solve the problem with the importing Its just importing and exporting
ambergristle
ambergristle4mo ago
you should only need to share types from a generated d.ts file between web and server i would recommend moving api and ui back into their respective /app directories. splitting them out seems like it would just complicate things if importing/exporting the types also errors, it's probably something to do with your tsconfig or another project config

Did you find this page helpful?