Skip to Content
ErrorsNEXUS_REQUEST_MISSING

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_REQUEST_MISSING

NEXUS_REQUEST_MISSING means ship.createScope() received no request while scoped providers depend on REQUEST. createScope returns a promise, so the call rejects. scope.extend() rejects with it too, when a module loaded later adds a REQUEST dependent and the scope has no request.

Reproduce NEXUS_REQUEST_MISSING

The region builds Mission from REQUEST and creates a scope with no request. Without a plugin, core prints a one-line message that starts with the code and ends with the address of this page. With errors() from @nexusdi/errors registered (npm install @nexusdi/errors@next), the same error carries the full text and its fix.

import { Nexus, REQUEST, Token, defineModule } from '@nexusdi/core'; import { isNexusError } from '@nexusdi/core'; import { provide } from '@nexusdi/core'; import { errors } from '@nexusdi/errors'; interface Mission { readonly id: string; readonly target: string; } interface IFlightLog { readonly mission: Mission; } const MISSION = new Token<Mission>('Mission'); const FLIGHT_LOG = new Token<IFlightLog>('FlightLog'); class ShuttleFlightLog implements IFlightLog { static deps = [MISSION] as const; constructor(readonly mission: Mission) {} } const Tactical = defineModule({ name: 'Tactical', providers: [ provide(MISSION, { useFactory: (request) => request.mission, deps: [REQUEST], lifetime: 'scoped', }), provide(FLIGHT_LOG, { useClass: ShuttleFlightLog, lifetime: 'scoped' }), ], exports: [FLIGHT_LOG], }); await using ship = await Nexus.create(Tactical); const thin = await ship.createScope().catch((error: unknown) => error); const line = isNexusError(thin) ? thin.message : null; // -> '[NEXUS_REQUEST_MISSING] dependents=Mission. https://nexus.js.org/errors/NEXUS_REQUEST_MISSING' console.log(line); await using fullShip = await Nexus.create(Tactical, { plugins: [errors()] }); const full = await fullShip.createScope().catch((error: unknown) => error); const text = isNexusError(full) ? full.message.split('\n') : null; // -> ['[NEXUS_REQUEST_MISSING] createScope() received no request, and Mission depends on REQUEST.', ' Fix: pass createScope({ request }).'] console.log(text);

Try it: save the region as error.ts and run npx tsx error.ts. It prints the one-line message, then the full text as an array of two strings. The dependents field names Mission. The regions read request.mission, so save the request.d.ts file from Scopes and the REQUEST Token beside them and tsc agrees. Then save the fix region below as fixed.ts and run npx tsx fixed.ts. It prints survey-7.

Fix NEXUS_REQUEST_MISSING

NEXUS_REQUEST_MISSING is fixed by passing the request: ship.createScope({ request }). The NexusRequest interface, which your project augments, declares its shape.

import { Nexus, REQUEST, Token, defineModule, provide } from '@nexusdi/core'; interface Mission { readonly id: string; readonly target: string; } interface IFlightLog { readonly mission: Mission; } const MISSION = new Token<Mission>('Mission'); const FLIGHT_LOG = new Token<IFlightLog>('FlightLog'); class ShuttleFlightLog implements IFlightLog { static deps = [MISSION] as const; constructor(readonly mission: Mission) {} } const Tactical = defineModule({ name: 'Tactical', providers: [ provide(MISSION, { useFactory: (request) => request.mission, deps: [REQUEST], lifetime: 'scoped', }), provide(FLIGHT_LOG, { useClass: ShuttleFlightLog, lifetime: 'scoped' }), ], exports: [FLIGHT_LOG], }); await using ship = await Nexus.create(Tactical); await using shuttle = await ship.createScope({ request: { mission: { id: 'survey-7', target: 'Kepler-442b' } }, }); const id = shuttle.get(FLIGHT_LOG).mission.id; // -> 'survey-7' console.log(id);

Try it: in fixed.ts, replace the whole ship.createScope({ ... }) call with ship.createScope() and run it again. tsc accepts the call. tsx throws an uncaught RequestMissingError that starts with [NEXUS_REQUEST_MISSING] dependents=Mission.. Put the request back and the program prints survey-7 again.

Fields of RequestMissingError

RequestMissingError has one field:

  • dependents: the names of the providers that depend on REQUEST. For extend(), only the providers the load added.