Skip to content

Type reflection issues #798

Closed
Closed

Description

@MirrorBytes

Describe the bug
Typescript metadata reflection does not seem to work at all. At first I thought it was related to the graphql adder, but it turns out that type-graphql works perfectly fine outside of sveltekit in an api folder served by vercel dev. This is not a permanent solution though considering there are existing issues pertaining to MIME types: #781.

Logs
This is produced in both the response and the dev console (not browser).

Error when evaluating SSR module /src/resolvers/user.ts:
Error: Unable to infer GraphQL type from TypeScript reflection system. You need to provide explicit type for argument named 'data' of 'register' of 'UserResolver' class.
    at Object.findType (/Users/bobby/Documents/phorm-kit-vercel/node_modules/type-graphql/dist/helpers/findType.js:19:15)
    at Object.getParamInfo (/Users/bobby/Documents/phorm-kit-vercel/node_modules/type-graphql/dist/helpers/params.js:10:49)
    at /Users/bobby/Documents/phorm-kit-vercel/node_modules/type-graphql/dist/decorators/Arg.js:14:25
    at eval (/src/resolvers/user.ts:14:54)
    at __decorate (/src/resolvers/user.ts:9:24)
    at eval (/src/resolvers/user.ts:74:1)
    at instantiateModule (/Users/bobby/Documents/phorm-kit-vercel/node_modules/vite/dist/node/chunks/dep-66eb515d.js:69030:166) (x18)
Error: Unable to infer GraphQL type from TypeScript reflection system. You need to provide explicit type for argument named 'data' of 'register' of 'UserResolver' class.
    at Object.findType (/Users/bobby/Documents/phorm-kit-vercel/node_modules/type-graphql/dist/helpers/findType.js:19:15)
    at Object.getParamInfo (/Users/bobby/Documents/phorm-kit-vercel/node_modules/type-graphql/dist/helpers/params.js:10:49)
    at /Users/bobby/Documents/phorm-kit-vercel/node_modules/type-graphql/dist/decorators/Arg.js:14:25
    at eval (/src/resolvers/user.ts:14:54)
    at __decorate (/src/resolvers/user.ts:9:24)
    at eval (/src/resolvers/user.ts:74:1)
    at instantiateModule (/Users/bobby/Documents/phorm-kit-vercel/node_modules/vite/dist/node/chunks/dep-66eb515d.js:69030:166)

To Reproduce
Create a new sveltekit project, use graphql adder, and create an object and resolver using type-graphql.
You can also look here: https://github.com/MirrorBytes/phorm-kit-vercel

Expected behavior
For metadata reflection to function.

Information about your SvelteKit Installation:

System:
    OS: macOS 11.2.3
    CPU: (8) arm64 Apple M1
    Memory: 373.55 MB / 8.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 15.12.0 - /opt/homebrew/bin/node
    Yarn: 1.22.10 - /opt/homebrew/bin/yarn
    npm: 7.7.5 - /opt/homebrew/bin/npm
  Browsers:
    Brave Browser: 89.1.22.70
    Safari: 14.0.3
  npmPackages:
    @sveltejs/kit: next => 1.0.0-next.64
    svelte: ^3.29.0 => 3.36.0
  • Your browser
    Brave & Safari

  • Your adapter (e.g. Node, static, Vercel, Begin, etc...)
    Vercel

Severity
How severe an issue is this bug to you? Is this annoying, blocking some users, blocking an upgrade or blocking your usage of SvelteKit entirely?

It's a hindrance to me and potentially anyone using TypeScript with decorators.
I'm reproducing an existing project that currently exists in plain Svelte, so it's just a mild inconvenience at the moment, but it's ultimately blocking me from moving forward with SvelteKit.

Activity

  1. benmccann commented on Mar 31, 2021

    @benmccann
    Member

    This seems too specific to GraphQL to be something that we could really address without more details as to what the cause of the issue is. You might try seeing if this happens with a standard Vite app: npm init @vitejs/app

  2. MirrorBytes commented on Mar 31, 2021

    @MirrorBytes
    Author

    Same thing occurs with mikro-orm and typeorm. I'll try creating a vite app to see if it's related.

  3. MirrorBytes commented on Mar 31, 2021

    @MirrorBytes
    Author

    It works perfectly fine with vite considering the ssr is created by the user. I'm not sure how I could replicate this issue within vite without SvelteKit.

  4. MirrorBytes commented on Apr 1, 2021

    @MirrorBytes
    Author

    @benmccann Do you think if I wrote a plugin for vite and included it in svelte.config.cjs that it would work? Here's another repo that does something similar with Nest: https://github.com/axe-me/poc-vite-node-server/blob/main/vite-plugin-node.js

  5. babichjacob commented on May 4, 2021

    @babichjacob
  6. benmccann commented on May 4, 2021

    @benmccann
    Member

    Comment from @dummdidumm on the duplicate issue #1327:

    I guess that the underlying problem is that you use Vite there, which uses ESBuild, which does not support the emitDecoratorMetadata setting. You need to find a Vite plugin that transpiles TS/JS files with the tsc compiler.

    Here's the issue in the esbuild repo: evanw/esbuild#257

    Maybe we should document this in troubleshooting/FAQ

  7. gamelaster commented on May 5, 2021

    @gamelaster

    (in relation of #1327) according to this comment, there is no tsc plugin for Vite (yet?).

  8. dummdidumm commented on May 5, 2021

    @dummdidumm
    Member

    I found this npm package from a quick search, but I haven't tested it.

  9. hatemjaber commented on Jun 17, 2021

    @hatemjaber

    I'm not sure if this will help anyone or if you have a better solution, but here's the link #349 to a "solution" on another thread where I was asking for help regarding the ESM error that I was getting that is similar to what you're experiencing.

    If you do have a better solution please share.

  10. Glench commented on Jan 9, 2022

    @Glench

    Is there any update on this? TypeORM uses reflect-metadata and decorators which aren't supported by esbuild apparently so it's very difficult or maybe impossible to use one of the most popular ORMS with SvelteKit in addition to GraphQL :(

    It seems that maybe swc or some other builder could work, but there are no hooks in the sveltekit code that I'm aware of that can replace just the esbuild step. (Actually I don't understand the architecture well enough to know if that sentence even makes sense.)

  11. benmccann commented on Jan 9, 2022

    @benmccann
    Member

    esbuild has been removed from adapter-node, so this should work there now. It's still present in adapter-vercel, which is what this issue was originally filed about. I'm not sure why it's still there. Possibly it could be removed with a bit of work. It might be mentioned in one of the resolved reviews on #2931

  12. Glench commented on Jan 10, 2022

    @Glench

    Hm ok interesting! Maybe I misunderstood the original bug then, or misinterpreted the resulting discussion? My understanding is that vite uses esbuild under the hood so on a development server getting the type reflection metadata (like decorators) is impossible, which makes using libraries like the GraphQL adder or TypeORM difficult or impossible.

    I made a test repo for TypeORM/SvelteKit here. I'm getting a warning from the dev server when importing reflect-metadata — maybe this is the root issue? Then I get a "ColumnTypeUndefinedError" and the User entity is undefined. This is what happens when decorators aren't supported. Not sure if this is a SvelteKit thing or what, but I believe I have all the correct TypeORM settings listed on the quickstart. npm run preview also fails but for a different reason. Should I open a new issue?

  13. benmccann commented on Jan 10, 2022

    @benmccann
    Member

    Vite uses esbuild under the hood, but only for pre-bundling third-party libraries. It uses Rollup for the user's own code.

    Should I open a new issue?

    To be quite honest with you, I don't think anyone from the team would look at a TypeORM issue since it's somewhat uncommon and only happens with a technology none of us use. Just in terms of the huge number of issues we have, it's not going to be high enough priority that it'll really get looked at, so it needs to be someone from the community motivated to figure out what the issue is.

  14. Glench commented on Jan 10, 2022

    @Glench

    Ah, thanks for the clear answer! Maybe I'll grab someone from Discord. I'd like to confirm that there's nothing about SvelteKit that precludes TypeORM from working since TypeORM is the number 1 starred JS ORM on Github (and I'd like to use it 🙂)

  15. gamelaster commented on Jan 10, 2022

    @gamelaster

    @Glench I will try to look on this once again, I was trying to use TypeORM with SvelteKit too several months ago, but I had problem with Vite and esbuild too, although, there was some other issues with bundling too (which might still happen now?).

  16. Glench commented on Jan 11, 2022

    @Glench

    @Glench I will try to look on this once again, I was trying to use TypeORM with SvelteKit too several months ago, but I had problem with Vite and esbuild too, although, there was some other issues with bundling too (which might still happen now?).

    Awesome!

    I made a thread about the TypeORM stuff here for reference: https://www.reddit.com/r/sveltejs/comments/s0nov1/getting_errors_with_typeorm_and_sveltekit_any/

    Going to try not to keep spamming here in the discussion of this issue :)

  17. Glench commented on Jan 30, 2022

    @Glench

    Here's some discussion of this issue: #3334

  18. added this to the whenever milestone on Apr 25, 2022
  19. teemingc commented on May 21, 2026

    @teemingc
    Member

    Vite 8 no longer uses esbuild and we've also dropped it from all packages in the version-3 branch in #15432

  20. linked a pull request that will close this issuechore: migrate from esbuild to rolldown #15432on May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions