Aliheym / typeorm-transactional

A Transactional Method Decorator for TypeORM that uses Async Local Storage or cls-hooked to handle and propagate transactions between different repositories and service methods.
MIT License
201 stars 27 forks source link

TypeError: Cannot redefine property: manager #26

Open Leonelmarianog opened 1 year ago

Leonelmarianog commented 1 year ago

Hello,

Using this library with the following NestJS configuration (Webpack's Hot Module Replacement) makes the following error appear when reloading the app.

image

This doesn't break the app but is quite annoying in development.

I tried to fix it by following this question.

image

But it makes it worse.

error-typeorm-transactional-2

What can I do?.

Thanks!.

Leonelmarianog commented 1 year ago

Created a minimal reproduction repository for this: https://github.com/Leonelmarianog/typeorm-transactional-test

no-creative-name commented 1 year ago

I have the same error, though it only occurs when using the latest version (0.4.1). If I downgrade to 0.3.0 everything works flawlessly.

no-creative-name commented 1 year ago

For me it works when I wrap the call to initializeTransactionalContext into a conditional if statement, that checks if there is already a context initialized:

const transactionalContext = getTransactionalContext();
  if (!transactionalContext) {
    initializeTransactionalContext();
  }

getTransactionalContext is imported from typeorm-transactional/dist/common