didi is a lightweight, battle-tested Inversion of Control (IoC) container for JavaScript and TypeScript, primarily used for dependency injection. It allows decoupling component declaration from instantiation by defining modules that declare components by name and specify how they are provided (e.g., as types, factories, or static values). The library then instantiates components on demand, transitively resolves their dependencies, and caches instances for reuse. Currently at stable version 11.0.0, didi maintains a moderate release cadence, largely driven by maintenance and dependency updates, with major version bumps often related to module system changes (e.g., ESM-only). Its key differentiators include its minimal footprint, focus on core DI patterns, and proven use in mature projects like Karma and diagram-js, making it suitable for applications requiring robust, explicit dependency management.
npm install didiVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates defining components, configuring modules with type, factory, and value providers, and retrieving typed instances using the Injector.
Migrate all imports from `require('didi')` to `import { ... } from 'didi';`. Ensure your project's build configuration supports ES Modules. For Node.js, this means using `'type': 'module'` in `package.json` or using `.mjs` file extensions.Ensure your Node.js environment is at version 20.12 or higher before upgrading to didi v11.x.
Always use the static `$inject` property on constructors/factories (e.g., `Car.$inject = ['engine', 'license']`) or the array notation (e.g., `['engine', 'Car', function(engine) {}]`) when targeting environments where code minification is applied to avoid issues.Change `const { Injector } = require('didi');` to `import { Injector } from 'didi';` and ensure your project is configured for ES modules.Verify that 'dependencyName' is correctly defined in one of your didi modules using 'type', 'factory', or 'value' declaration. Check for typos in both the module definition and the injection point.
Ensure module definitions conform to `[ 'type' | 'factory' | 'value', ... ]` array structure. For example, `{'myService': ['type', MyService]}`.No dependency data recorded yet.