elysiajs / elysia

Ergonomic Framework for Humans
https://elysiajs.com
MIT License
10.15k stars 217 forks source link

Issue with Exporting Client in Monorepo with ReactJS and TurboRepo #603

Closed lyorb closed 5 months ago

lyorb commented 5 months ago

What version of Elysia.JS is running?

1.0.13

What platform is your computer?

Microsoft Windows NT 10.0.22631.0 x64

What steps can reproduce the bug?

I relied on this repository : elysia-monorepo-example

  1. Set up a monorepo architecture with ReactJS (ViteJS), ElysiaJS with TurboRepo.
  2. Create a package named "libs" within the packages folder.
  3. Attempt to export a client that imports the type App from the Elysia server using the Elysia Treaty module.
  4. Notice that when exporting the client, you are required to retype the client interface.
  5. Observe that this results in the loss of benefits provided by the Elysia Treaty module.

Not working code:

import { treaty } from "@elysiajs/eden";
import type { App } from "@app/bun-elysia";

export const client = treaty<App>("http://localhost:3000/");

Exported variable 'client' has or is using name 'Treaty.OnMessage' from external module "c:/Users/NAME/Desktop/projects/mono-elysia-react/node_modules/@elysiajs/eden/dist/index" but cannot be named.

Working code :

import { treaty } from "@elysiajs/eden";
import type { App } from "@app/bun-elysia";

interface MyClient {
  index: {};
  ws: {};
}

export const client: MyClient = treaty<App>("http://localhost:3000/");

What is the expected behavior?

The expected behavior is that the client can be exported without having to redefine the client interface, thus maintaining the benefits of using the Elysia Treaty module.

What do you see instead?

Instead, when attempting to export the client without redefining the client interface, the error mentioned above is encountered.

Additional information

No response

kayandra commented 5 months ago

hello @lyorb did you manage to fix this? I'm currently in the same bind.

lyorb commented 5 months ago

hello @lyorb did you manage to fix this? I'm currently in the same bind.

Hey @kayandra I just removed the declarative field from my tsconfig and that solved the problem

kayandra commented 5 months ago

hello @lyorb did you manage to fix this? I'm currently in the same bind.

Hey @kayandra I just removed the declarative field from my tsconfig and that solved the problem

I fixed mine by removing "paths" from the server build and it works. Hopefully, will put in more time to find a proper solution.