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

getDecorators is not a function #1509

Open
linonetwo opened this issue May 17, 2023 · 0 comments
Open

getDecorators is not a function #1509

linonetwo opened this issue May 17, 2023 · 0 comments

Comments

@linonetwo
Copy link

linonetwo commented May 17, 2023

Expected Behavior

Work in esm env

Current Behavior

console.log
    { default: [Function: getDecorators] }

This means

import { Container } from 'inversify';
import getDecorators from 'inversify-inject-decorators';
import 'reflect-metadata';

export const container = new Container();
export const { lazyInject } = getDecorators(container);

have to change to

export const { lazyInject } = getDecorators.default(container);

Possible Solution

maybe its jsnext:main is not pickup by jest.

Change package.json of this package to "main": "es/index.js", can solve this

and change them to mjs

截屏2023-05-17 16 24 59

Steps to Reproduce (for bugs)

I set up ts jest using

    "test": "NODE_OPTIONS=--experimental-vm-modules jest -c jest.config.ts"

jest.config.ts

import type { JestConfigWithTsJest } from 'ts-jest';

const jestConfig: JestConfigWithTsJest = {
  preset: 'ts-jest/presets/js-with-ts-esm',
  testEnvironment: 'node',
  extensionsToTreatAsEsm: ['.ts'],
  globals: {
    'ts-jest': {
      useESM: true,
      isolatedModules: true,
    },
  },
  roots: ['<rootDir>/src/', '<rootDir>/tests/'],
};

export default jestConfig;

Context

Maybe it is time to provide a esm version of that package, without feature change.

Your Environment

  • Version used:
    "inversify": "^6.0.1",
    "inversify-inject-decorators": "^3.1.0",
    "reflect-metadata": "^0.1.13"
  • Environment name and version (e.g. Chrome 39, node.js 5.4):
 node -v                       
v18.12.1
  • Operating System and version (desktop or mobile): Mac 13.3.1 (a) (22E772610a)

Stack trace

  ● Test suite failed to run

    TypeError: getDecorators is not a function

      4 |
      5 | export const container = new Container();
    > 6 | export const { lazyInject } = getDecorators(container);
        |                               ^
      7 |

      at src/iocContainer/container.ts:6:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant