Debug
Import scripts of redi more than once
[redi]: You are loading scripts of redi more than once! This may cause undesired behavior in your application. Maybe your dependencies added redi as its dependency and bundled redi to its dist files. Or you import different versions of redi.
This error happens when you import scripts of redi more than once. This usually happens when
- Some dependency in your workspace uses redi as well. However, it don’t declare redi as an external dependency.
- Some dependency in your project uses a different version of redi from yours.
- You are working on a monorepo and repos uses different versions of redi.
redi use Symbol
and instanceof
internally. So things may not work when you import redi more than once. To fix this problem:
- Contact the maintainer of these dependencies and ask them set redi as an external dependency.
- The dependency may re-exports API of redi. In such case you should use these re-exported API instead of using redi directly.
- Use the same version of redi across your monorepo.
Could not find dependency registered on
[redi]: It seems that you register “undefined” as dependency on the X parameter of “XXX”. Please make sure that there is not cyclic dependency among your TypeScript files, or consider using “forwardRef”.
This errors happens when redi is trying to figure out what dependencies XXX
relies on but a dependency is resolved to undefined
.
Let’s assume that the dependency resolved to undefined
is YYY
.
YYY
must be a class type dependency.- Due to how TypeScript is transpiled into JavaScript.
YYY
is declared first and later assigned to the constructor function ofYYY
. - There is cycle dependency among your TypeScript files that leads to
YYY
being evaluated asundefined
whenInject
decorator is trying to registerYYY
as a dependency onXXX
.
To fix this problem, you can use forwardRef
import { Inject, forwardRef } from "@wendellhu/redi";
class XXX {
constructor(@Inject(forwardRef(() => YYY)) private readonly _yyy: YYY) {}
}
… or fix cycle dependency in your codebase. We recommend using dpdm to find cycle dependency in your codebase. You could traverse the dependency tree staring from the file that contains XXX
, and break cycles those contains the file.