Skip to Content
Error codes

This page documents the 0.4 release candidates of @nexusdi/core. The newest on npm is 0.4.0-rc.1. The documentation for 0.3.2, the current release, is at nexus.js.org. Try the release candidate.

Error Codes Reference

Every error raised by NexusDI carries a stable code. By default, these errors provide a concise one-line message and a link to the specific documentation page for that code. When the @nexusdi/errors or @nexusdi/devtools plugins are registered, these codes are expanded into full human-readable messages with suggested fixes.

You can use the isNexusError(error, code) utility from @nexusdi/core to detect specific errors and narrow the error to its specific class. Check where the code arrives: most graph errors arrive inside the errors list of NEXUS_BLUEPRINT_INVALID, and an error raised while a provider is built arrives as the cause of NEXUS_PROVIDER_FAILED. How Each Code Arrives at the end of this page lists the way for every code.

A package that adds codes declares them in the NexusErrorByCode interface, and Writing NexusDI Plugins shows how.

Core Error Codes

These errors are raised by @nexusdi/core during graph validation or container resolution.

CodeClassDescription
NEXUS_BLUEPRINT_INVALIDBlueprintErrorThe module graph is invalid; see the errors array for specific issues.
NEXUS_MISSING_PROVIDERMissingProviderErrorA dependency token has no visible provider.
NEXUS_AMBIGUOUS_PROVIDERAmbiguousProviderErrorA module imports two or more modules that each export their own provider of the same token.
NEXUS_DUPLICATE_PROVIDERDuplicateProviderErrorA single module defines the same provider multiple times.
NEXUS_INVALID_EXPORTInvalidExportErrorA module attempts to export a token it does not provide or import.
NEXUS_INVALID_PROVIDERInvalidProviderErrorA provider definition is malformed.
NEXUS_INVALID_TOKENInvalidTokenErrorA value is used as a token but is not a class or a Token instance, or a Token has an empty description.
NEXUS_INVALID_MODULEInvalidModuleErrorA value used as a module is not a defineModule result or @Module class.
NEXUS_MISSING_DEPSMissingDepsErrorA class with constructor parameters is missing its static deps list.
NEXUS_CIRCULAR_DEPENDENCYCircularDependencyErrorA dependency loop was detected with no lazy() edge to break it.
NEXUS_LIFETIME_VIOLATIONLifetimeErrorA singleton depends on a scoped provider or on REQUEST (Captive Dependency).
NEXUS_MODULE_IMPORT_CYCLEModuleImportCycleErrorTwo or more modules import each other in a loop.
NEXUS_MODULE_OPTIONS_MISSINGModuleOptionsErrorA configurable module was imported without forRoot or forRootAsync.
NEXUS_LOAD_GLOBAL_MODULELoadErrorload() received a global module, or a module that imports a global module the graph lacks.
NEXUS_INVALID_MODULE_OPTIONSModuleOptionsErrorModule options failed the defined schema validation.
NEXUS_PROVIDER_FAILEDProviderErrorA constructor, factory, onInit, or options validation threw an error during instantiation.
NEXUS_NOT_READYNotReadyErrorA lazy() thunk was called before the target provider was initialized.
NEXUS_ASYNC_TRANSIENTAsyncTransientErrorA transient factory returned a promise (transients must be synchronous).
NEXUS_LAZY_ASYNCLazyAsyncErrorAn eager: false provider, or its onInit, returned a promise on first use.
NEXUS_NOT_VISIBLENotVisibleErrorThe token exists, but the requesting module cannot see it.
NEXUS_SCOPE_REQUIREDScopeRequiredErrorA scoped provider was requested from the root container.
NEXUS_REQUEST_MISSINGRequestMissingErrorcreateScope was called without a request object while scoped providers depend on REQUEST.
NEXUS_LOADED_AFTER_SCOPELoadedAfterScopeErrorA token was loaded into the root after the current scope was created.
NEXUS_DISPOSEDDisposedErrorThe container or scope was used after being disposed.
NEXUS_PLUGIN_INVALIDPluginErrorA plugin passed to Nexus.create or Nexus.check is malformed.
NEXUS_PLUGIN_VERSIONPluginErrorA plugin declares a plugin API version this core does not support.
NEXUS_PLUGIN_CONFLICTPluginErrorTwo plugins rewrite the same module or provider.
NEXUS_PLUGIN_FAILEDPluginErrorA plugin hook threw or returned a value of the wrong type.

Error Codes from Other Packages

These errors are raised by the other official NexusDI packages.

PackageCodeClassDescription
@nexusdi/interceptorsNEXUS_INTERCEPTOR_INVALIDInterceptorErrorInterceptor definition or call is malformed.
@nexusdi/interceptorsNEXUS_INTERCEPTOR_MISSINGInterceptorErrorA declared interceptor was not registered in the plugin.
@nexusdi/interceptorsNEXUS_INTERCEPTOR_LIFETIMEInterceptorErrorAn interceptor was marked as scoped or transient.
@nexusdi/interceptorsNEXUS_INTERCEPTOR_NOT_READYInterceptorErrorInterceptor called before build or after disposal.
@nexusdi/interceptorsNEXUS_INTERCEPTORS_SHAREDInterceptorErrorAn interceptors plugin object was passed to a second container while another container still holds it.
@nexusdi/interceptorsNEXUS_INTERCEPTORS_UNCHECKEDInterceptorErrorAn instance was wrapped without being checked by the compiler.
@nexusdi/testingNEXUS_OVERRIDE_UNUSEDOverrideErrorAn override names a token that no provider binds, or a module the graph never imports.
@nexusdi/testingNEXUS_OVERRIDE_EXPORTSOverrideErrorA module stub doesn’t export everything the original did.
@nexusdi/decoratorsNEXUS_LEGACY_DECORATORSLegacyDecoratorsErrorA decorator ran under experimentalDecorators.
@nexusdi/devtoolsNEXUS_DEVTOOLS_UNREGISTEREDDevtoolsErrorgraph() called on a container without the devtools plugin.
@nexusdi/devtoolsNEXUS_DEVTOOLS_GRAPH_INVALIDDevtoolsErrorThe provided JSON is not a valid NexusGraph.
@nexusdi/federationNEXUS_CONTRACT_VERSIONContractVersionErrorA dependent needs a contract version its provider does not satisfy.

How Each Code Arrives

isNexusError(e, code) on the top-level error matches only a code that arrives bare. A code found inside NEXUS_BLUEPRINT_INVALID sits in that error’s errors list, and a cause sits in the cause of NEXUS_PROVIDER_FAILED.

  • Found inside NEXUS_BLUEPRINT_INVALID: NEXUS_AMBIGUOUS_PROVIDER, NEXUS_DUPLICATE_PROVIDER, NEXUS_INVALID_EXPORT, NEXUS_INVALID_PROVIDER, NEXUS_MISSING_DEPS, NEXUS_CIRCULAR_DEPENDENCY, NEXUS_LIFETIME_VIOLATION, NEXUS_MODULE_IMPORT_CYCLE, NEXUS_MODULE_OPTIONS_MISSING, NEXUS_PLUGIN_INVALID, NEXUS_PLUGIN_VERSION, NEXUS_PLUGIN_CONFLICT, NEXUS_CONTRACT_VERSION, NEXUS_INTERCEPTOR_MISSING, NEXUS_INTERCEPTOR_LIFETIME, NEXUS_OVERRIDE_UNUSED and NEXUS_OVERRIDE_EXPORTS.
  • NEXUS_BLUEPRINT_INVALID itself: thrown by Nexus.create, Nexus.check, validate() and load(), with errors listing each problem.
  • Bare or inside, by caller: get() and resolve() throw NEXUS_MISSING_PROVIDER bare for a token no module provides, and Nexus.create and validate() report it inside NEXUS_BLUEPRINT_INVALID. NEXUS_INVALID_TOKEN follows the same split, and new Token('') throws it bare too. load(), defineModule() and the module option of get() throw NEXUS_INVALID_MODULE bare, and Nexus.create reports a bad imports entry inside NEXUS_BLUEPRINT_INVALID.
  • As the cause of NEXUS_PROVIDER_FAILED: NEXUS_INVALID_MODULE_OPTIONS, a NEXUS_NOT_READY raised while Nexus.create builds, and any error a constructor, a factory or an onInit throws.
  • NEXUS_PLUGIN_FAILED: a setup hook and a tokenKey hook met in a lookup throw it bare, a compile hook reports it inside NEXUS_BLUEPRINT_INVALID, and a construct hook makes it the cause of NEXUS_PROVIDER_FAILED. Its own cause holds the hook’s error.
  • NEXUS_INTERCEPTOR_INVALID: the compile reports it inside NEXUS_BLUEPRINT_INVALID, @UseInterceptors throws it bare, and a build fault makes it the cause of NEXUS_PROVIDER_FAILED. Its reason names the rule.
  • NEXUS_INTERCEPTORS_SHARED: reported inside NEXUS_BLUEPRINT_INVALID, or the cause of NEXUS_PROVIDER_FAILED when two creates overlap.
  • Thrown bare: every other code, from the call that hits it: NEXUS_LOAD_GLOBAL_MODULE from load(), NEXUS_NOT_VISIBLE and NEXUS_SCOPE_REQUIRED from a lookup, NEXUS_REQUEST_MISSING from createScope(), NEXUS_DISPOSED after disposal started, and the devtools and decorators codes from the call that raised them.