bun icon indicating copy to clipboard operation
bun copied to clipboard

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

Open PodaruDragos opened this issue 9 months ago • 4 comments

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 avatar May 17 '24 15:05 PodaruDragos