Skip to content

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

  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...

💡

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.

  1. XXX is a class type dependency
  2. Due to how TypeScript is transpiled into JavaScript. XXX is declared first and later assigned to the constructor function of XXX.
  3. There is cycle dependency among your TypeScript files that leads to XXX being evaluated as undefined when Inject decorator is trying to register XXX 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.