typestack / typedi

Simple yet powerful dependency injection tool for JavaScript and TypeScript.
https://docs.typestack.community/typedi/v/develop/01-getting-started
MIT License
4.07k stars 169 forks source link

fix: Error when running in bunjs runtime #1299

Closed mxyhi closed 9 months ago

mxyhi commented 9 months ago
import "reflect-metadata";

import { injectable, singleton, container } from 'tsyringe';

console.log(Reflect.getMetadata)
@injectable()
class Database {
  constructor() {}

  run() {
    console.log('run');
  }
}

@singleton()
class Foo {
  constructor(public database: Database) {}
}

const instance = container.resolve(Foo);
console.log(Reflect.getMetadata)

instance.database.run();

2 | Object.defineProperty(exports, "__esModule", { value: true });
3 | const tslib_1 = require("tslib");
4 | console.log(Reflect)
5 | console.log(Reflect.getMetadata)
6 | if (typeof Reflect === "undefined" || !Reflect.getMetadata) {
7 |     throw new Error(`tsyringe requires a reflect polyfill. Please add 'import "reflect-metadata"' to the top of your entry point.`);
              ^
error: tsyringe requires a reflect polyfill. Please add 'import "reflect-metadata"' to the top of your entry point.
      at /Users/mxy/Documents/workspace/bun/demo/node_modules/tsyringe/dist/cjs/index.js:7:11
attilaorosz commented 9 months ago

You are using tsyringe not typedi.

github-actions[bot] commented 8 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.