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

Problem with decorators: Reflect.hasOwnMetadata is not a function. #11152

Open
PodaruDragos opened this issue May 17, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@PodaruDragos
Copy link

PodaruDragos commented May 17, 2024

What version of Bun is running?

1.1.7+b0b7db5c0

What platform is your computer?

Microsoft Windows NT 10.0.22631.0 x64

What steps can reproduce the bug?

While using inversify.js i get the error in the title.

Steps to reproduce this:

Create 3 files like so.

File 1

// index.ts
import 'reflect-metadata';
import { what } from './file-3.js';

File 2

file-2.ts
import { inject, injectable } from 'inversify';


@injectable()
export class Child {
  public test() {
    return 'test';
  }
}

@injectable()
export class Test {
  constructor(
    @inject('CHILD') private child: Child
  ) { }

  public test() {
    return this.child.test();
  }
}

File 3

import { Container } from 'inversify';
import { Child, Test } from './file-2.js';


class CContainer {
  public container: Container;
  constructor() {
    this.container = new Container();
    this.container.bind('CHILD').to(Child);
    this.container.bind('TEST').to(Test);
  }
}

const cc = new CContainer();
const test = cc.container.get<Test>('TEST');


export const what = (): string => {
  return test.test();
};

Run bun run index.ts and you should get the error.

What is the expected behavior?

I would expect the output to be test

What do you see instead?

TypeError: Reflect.hasOwnMetadata is not a function. (In 'Reflect.hasOwnMetadata(metadataKey, annotationTarget)', 'Reflect.hasOwnMetadata' is undefined)

Additional information

If all the code is one file, it works just fine

@PodaruDragos PodaruDragos added the bug Something isn't working label May 17, 2024
@levii-pires
Copy link

This has to do with the fact that bun does not use the same global for all modules (or so it seems)

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

2 participants