elysia icon indicating copy to clipboard operation
elysia copied to clipboard

Elysia fails to generate types when used with path aliases

Open Pedromigacz opened this issue 1 year ago • 8 comments

What version of Elysia is running?

elysia": "^1.1.22

What platform is your computer?

No response

What steps can reproduce the bug?

  1. Qucikstart an ElysiaJs project with bun create elysia app
  2. Add an import alias to your tsconfig.json. Ex:
"paths": { "@/*": ["./*"] }
  1. Use this import alias anywhere on your code to import a ElysiaJs instance. The most obvious issue happens when you import an ElysiaJs instance that is used for route splitting.
  2. Your elysia main instace won't have the types of the other ones. This makes eden unusable as a side effect.

What is the expected behavior?

ElysiaJs should know how to handle with import aliases. Independent of them being on a monorepo or not.

What do you see instead?

Elysia type system breaks

Additional information

This might be happening on monorepos only. I will investigate once I find time and report back.

Have you try removing the node_modules and bun.lockb and try again yet?

Yes

Pedromigacz avatar Oct 21 '24 12:10 Pedromigacz

I created this issue and this PR to warn users about this issue until I or someone figure out how to solve it.

Pedromigacz avatar Oct 21 '24 12:10 Pedromigacz

They shouldn't break nothing. Does typings equal?

kravetsone avatar Oct 21 '24 18:10 kravetsone

I will provide a easy way to reproduce the issue. Do you know, in the meantime, where can I find the generated types from elysia/eden?

Pedromigacz avatar Oct 22 '24 18:10 Pedromigacz

I will provide a easy way to reproduce the issue. Do you know, in the meantime, where can I find the generated types from elysia/eden?

It is not generated Elysia is just TypeScript

kravetsone avatar Oct 22 '24 19:10 kravetsone

You can use the references property in tsconfig.json to include the tsconfig from the backend in the frontend.

This is not an Elysia issue, this is a TypeScript configuration issue.

ap0nia avatar Oct 24 '24 21:10 ap0nia

did anybody fix it cause i am having the same issues

firstaxel avatar Mar 28 '25 18:03 firstaxel

@Pedromigacz @SaltyAom @ap0nia tried everything it is not working

firstaxel avatar Mar 29 '25 17:03 firstaxel

@Pedromigacz @SaltyAom @ap0nia tried everything it is not working

firstaxel avatar Mar 29 '25 17:03 firstaxel

See https://elysiajs.com/eden/installation.html#path-alias-monorepo

Closing as complete

SaltyAom avatar Aug 05 '25 16:08 SaltyAom

Just as a warning to anyone reading this:

After a long time working with monorepos and hitting issues like this one (on multiple things like nextJs, hono, elysia, mastra, react-native, etc) the thing that solved this for good is the following:

  • If the package is small, don't use path aliases.
  • If the package grows to a point you need it, make it a compiled package (instead of a JIT package). This is a good example you can use, but you can go a lot further using actual bundlers:
    // tsc-alias is the important thing
    "build": "tsc -p ./tsconfig.json && tsc-alias",
    "dev": "tsc -p ./tsconfig.json --watch & tsc-alias -p ./tsconfig.json --watch"

The reason this usually happens is because the bundler these frameworks use are not aware of other tsconfig files.

Pedromigacz avatar Oct 09 '25 14:10 Pedromigacz