elysiajs / eden

Fully type-safe Elysia client
MIT License
162 stars 39 forks source link

Server side dependencies prevent client side compilation #18

Closed framp closed 1 year ago

framp commented 1 year ago

Hello!

If I have @elysiajs/static or @elysia/apollo-graphql in my server definition client side compilation will fail. This is happening because of inner dependencies which are not available in the browser environment.

While it can be solved and handled (for example, by splitting your eden-safe plugins and unsafe ones and applying the unsafe ones in a different files), I think it points to an underlying limitation.

Am I missing something? If not, do you think we can improve the situation with a specific bun build configuration? Shall we consider an alternative route where we produce a static specification of the API and embed a simple JSON in the client?

Error details:

Apollo:

error: No matching export in "node:zlib" for import "gzip"

import { gzip } from 'zlib';
         ^
elysia-demo/node_modules/@elysiajs/apollo/node_modules/@apollo/server/dist/esm/plugin/usageReporting/plugin.js:8:10 377

Static:

error: No matching export in "node:path" for import "resolve"

import { resolve, resolve as resolveFn, join } from 'path';
         ^
elysia-demo/node_modules/@elysiajs/static/dist/index.js:2:10 54

error: No matching export in "node:path" for import "resolve"

import { resolve, resolve as resolveFn, join } from 'path';
                  ^
elysia-demo/node_modules/@elysiajs/static/dist/index.js:2:19 63

error: No matching export in "node:path" for import "join"

import { resolve, resolve as resolveFn, join } from 'path';
                                        ^
elysia-demo/node_modules/@elysiajs/static/dist/index.js:2:41 85

Cheers

framp commented 1 year ago

My bad, I was importing something else from the same file!

The proper solution is to only import the type

import type { ElysiaApp } from "..";

and not

import { ElysiaApp, origin } from "..";