Skip to Content
ErrorsNEXUS_OVERRIDE_UNUSED

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.

NEXUS_OVERRIDE_UNUSED

createTestingContainer(root).create() reports NEXUS_OVERRIDE_UNUSED when an override(TOKEN, ...) call names a token that no provider in the module graph binds, or an overrideModule(module, stub) call names a module that the graph never imports. The testing container runs the full compiler, so an override that replaces nothing fails the test at create and the test never runs against a graph it does not describe. create() rejects with NEXUS_BLUEPRINT_INVALID holding the error, and no call raises NEXUS_OVERRIDE_UNUSED bare. The check runs at create() only. An overrideModule(module, stub, { lazy: true }) call is exempt, because a later ship.load() may bring the module in.

Reproduce NEXUS_OVERRIDE_UNUSED

The test overrides NAV_CHARTS, and the module under test provides only REACTOR. @nexusdi/testing writes this message itself, so it carries its full text and fix line with no text pack, and errors({ text }) leaves it as written.

import { Token, defineModule, isNexusError, provide } from '@nexusdi/core'; import { createTestingContainer } from '@nexusdi/testing'; interface IReactorCore { readonly output: number; } interface INavCharts { plot(to: string): string; } const REACTOR = new Token<IReactorCore>('ReactorCore'); const NAV_CHARTS = new Token<INavCharts>('NavCharts'); const fakeCharts: INavCharts = { plot: (to) => `loopback course to ${to}` }; class FusionReactor implements IReactorCore { readonly output = 1.21; } const Engineering = defineModule({ name: 'Engineering', providers: [provide(REACTOR, { useClass: FusionReactor })], exports: [REACTOR], }); // Engineering provides no NAV_CHARTS, so the override replaces nothing. const error = await createTestingContainer(Engineering) .override(NAV_CHARTS, { useValue: fakeCharts }) .create() .catch((caught: unknown) => caught); const inner = isNexusError(error, 'NEXUS_BLUEPRINT_INVALID') ? error.errors[0] : undefined; const lines = inner?.message.split('\n'); // -> ['[NEXUS_OVERRIDE_UNUSED] override(NavCharts) matched no provider in the module graph.', ' Fix: remove the override, or import the module that provides NavCharts.'] console.log(lines?.join('\n'));

Try it: run npm install @nexusdi/core@next and npm install -D @nexusdi/testing@next, save the region as override.ts and run npx tsx override.ts. It prints the two-line message with its Fix: line: [NEXUS_OVERRIDE_UNUSED] override(NavCharts) matched no provider in the module graph. and Fix: remove the override, or import the module that provides NavCharts. Then add provide(NAV_CHARTS, { useValue: fakeCharts }) to the providers of Engineering and run it again. The override replaces that provider, the container builds, and the region prints undefined because there is no error to read.

Fix NEXUS_OVERRIDE_UNUSED

NEXUS_OVERRIDE_UNUSED goes away when the root passed to createTestingContainer imports the module that provides the overridden token, or when the test drops the override. An override for a module that a later ship.load() adds belongs on overrideModule(module, stub, { lazy: true }).

import { Token, defineModule, provide } from '@nexusdi/core'; import { createTestingContainer } from '@nexusdi/testing'; interface INavCharts { plot(to: string): string; } const NAV_CHARTS = new Token<INavCharts>('NavCharts'); const Tactical = defineModule({ name: 'Tactical', providers: [ provide(NAV_CHARTS, { useFactory: async (): Promise<INavCharts> => ({ plot: (to) => `course to ${to}`, }), }), ], exports: [NAV_CHARTS], }); const Meridian = defineModule({ name: 'Meridian', imports: [Tactical] }); const fakeCharts: INavCharts = { plot: (to) => `loopback course to ${to}` }; await using ship = await createTestingContainer(Meridian) .override(NAV_CHARTS, { useValue: fakeCharts }) .create(); const course = ship.get(NAV_CHARTS).plot('Kepler-442b'); // -> 'loopback course to Kepler-442b' console.log(course);

Try it: save the region as fixed.ts and run npx tsx fixed.ts. It prints loopback course to Kepler-442b. Change imports: [Tactical] in Meridian to imports: [] and run it again. npx tsc accepts the file, and npx tsx fixed.ts throws an uncaught BlueprintError and prints a stack trace headed BlueprintError: [NEXUS_BLUEPRINT_INVALID] 1 error. Put the import back and the program prints loopback course to Kepler-442b again.

Fields of OverrideError

  • code: 'NEXUS_OVERRIDE_UNUSED' or 'NEXUS_OVERRIDE_EXPORTS'.
  • token: for NEXUS_OVERRIDE_UNUSED, the name of the unused override: the token’s name, such as 'NavCharts', or the module’s name for an unused overrideModule(), such as 'Comms'. null for NEXUS_OVERRIDE_EXPORTS.
  • module: null for NEXUS_OVERRIDE_UNUSED.
  • missing: an empty array for NEXUS_OVERRIDE_UNUSED.