Debug
You are loading 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. For more info please visit our website.
This error happens when you import scripts of redi more than once. This usually happens when
- Some dependencies in your workspace use
@wendellhu/redi
as well. However, they don't use redi as a peer dependency and avoid bundling redi. - You are working on a monorepo and packages 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
@wendellhu/redi
as an external dependency and add it intopeerDependencies
instead ofdependencies
. - Use the same version of redi across your monorepo.
Could not find dependency registered on...
Could not find dependency registered on the N (indexed) parameter of the constructor of XXX.
This errors happens when redi is trying to figure out what dependencies XXX relies on but a dependency is resolved to undefined
.
XXX
is a class type dependency- Due to how TypeScript is transpiled into JavaScript. XXX is declared first and later assigned to the constructor function of
XXX
. - There is cycle dependency among your TypeScript files that leads to
XXX
being evaluated asundefined
whenInject
decorator is trying to registerXXX
as a dependency on the consumer.
To fix this problem, you can use forwardRef
import { Inject, forwardRef } from '@wendellhu/redi'class Consumer { constructor(@Inject(forwardRef(() => XXX)) private readonly _xxx: XXX) {}}
... or fix cycle dependency in your codebase.