Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emitDecoratorMetadata is not working properly! #4575

Closed
JawadAhbab opened this issue Sep 8, 2023 · 9 comments
Closed

emitDecoratorMetadata is not working properly! #4575

JawadAhbab opened this issue Sep 8, 2023 · 9 comments
Labels
bug Something isn't working

Comments

@JawadAhbab
Copy link

JawadAhbab commented Sep 8, 2023

What version of Bun is running?

0.8.1+16b4bf341acc0f4804f0b6bdf5298c180cd00366

What platform is your computer?

Darwin 22.6.0 arm64 arm

What steps can reproduce the bug?

import 'reflect-metadata'

const Decor = () => {
  return (target: any, name: string) => {
    const reflect = Reflect.getMetadata('design:type', target, name)
    console.log(reflect) // undefined
  }
}

class MyClass {
  @Decor() prop: string
}

tsconfig.json

{
  "compilerOptions": {
    "target": "ES2021",
    "module": "ES2022",
    "moduleResolution": "node",
    "types": ["bun-types"],
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "forceConsistentCasingInFileNames": true,
    "strict": false,
    "skipLibCheck": true
  }
}

Here reflect is undefined. It means design:type not reflected but in tsconfig emitDecoratorMetadata is true. (I guess) emitDecoratorMetadata is not working.

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

@JawadAhbab JawadAhbab added the bug Something isn't working label Sep 8, 2023
@sirenkovladd
Copy link
Contributor

I guess it is related https://github.com/oven-sh/bun/tree/dylan/emit-decorator-metadata

@JawadAhbab
Copy link
Author

I guess it is related https://github.com/oven-sh/bun/tree/dylan/emit-decorator-metadata

Any update about this branch?

@daniel-nagy
Copy link

I have the same issue. I was able to use a plugin to transpile files with decorators using TypeScript, which worked, but then ran into this issue #4689.

For reference I'm currently using TypeGraphQL which relies on decorator metadata.

@Zikoat
Copy link

Zikoat commented Sep 13, 2023

This is blocking TypeGraphQL and TypeORM for us.

@daniel-nagy Do you have the plugin you are talking about? Or is this something you cooked up?

@daniel-nagy
Copy link

@Zikoat I'm using a fork of https://github.com/thomaschaaf/esbuild-plugin-tsc to support esm, see thomaschaaf/esbuild-plugin-tsc#20. Also see #5111. You would need to modify the plugin to always return the file content.

@ecattez
Copy link

ecattez commented Sep 22, 2023

I guess it is related https://github.com/oven-sh/bun/tree/dylan/emit-decorator-metadata

Any update about this branch?

Branch seems to have been merged on main: 4a1573e
https://bun.sh/blog/bun-v1.0.3

@octet-stream
Copy link

octet-stream commented Sep 22, 2023

Bun v1.0.3 released with emitDecoratorMetadata support: https://github.com/oven-sh/bun/releases/tag/bun-v1.0.3

Just tried it MikroORM and it seem to work (I can clearly see metadata in compiled code and corresponding types in database schema).

@JawadAhbab
Copy link
Author

Fixed in Bun v1.0.3 🎉🎉🎉

@Bielik20
Copy link

I am not sure I should be writing it here or on #5000
but --tsconfig-override doesn't work with that (or at all).

I have a monorepo setting with a command to run from the root of the repository (it does not have tsconfig.json file there).

bun apps/customer-sls/bun-bundle.ts --tsconfig-override ./apps/customer-sls/tsconfig.app.json

bun-bundle.ts is just a file that executes Bun.build. For decorators metadata to work I need to create tsconfig.json at the repository root. Pointing with --tsconfig-override has no effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants