InversifyJS
InversifyJS copied to clipboard
getDecorators is not a function
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
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