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

  1. Some dependencies in your workspace use @wendellhu/redi as well. However, they don't use redi as a peer dependency and avoid bundling redi.
  2. 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:

  1. Contact the maintainer of these dependencies and ask them set @wendellhu/redi as an external dependency and add it into peerDependencies instead of dependencies.
  2. 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.

  1. YYY must be a class type dependency.
  2. Due to how TypeScript is transpiled into JavaScript. YYY is declared first and later assigned to the constructor function of YYY.
  3. There is cycle dependency among your TypeScript files that leads to YYY being evaluated as undefined when Inject decorator is trying to register YYY as a dependency on XXX.

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 (opens in a new tab) 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.