Skip to Content
ErrorsNEXUS_NOT_VISIBLE

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_NOT_VISIBLE

NEXUS_NOT_VISIBLE means a lookup asked for a token that some module provides and the lookup module cannot see. get() on the root, which resolves only what the root module sees, and get() on a scope throw it directly. So does resolve() for a required or lazy entry, while an optional entry gives undefined. validate() reports it inside NEXUS_BLUEPRINT_INVALID. When a provider’s own dependency is invisible, Nexus.create reports NEXUS_MISSING_PROVIDER inside NEXUS_BLUEPRINT_INVALID. With errors() registered, its nearMisses name the module that keeps the token private.

Reproduce NEXUS_NOT_VISIBLE

The region provides SubspaceLink in Comms, which exports nothing, and asks the root for it. 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, Token, defineModule, isNexusError } from '@nexusdi/core'; import { provide } from '@nexusdi/core'; import { errors } from '@nexusdi/errors'; interface ISubspaceLink { readonly frequency: number; } const SUBSPACE_LINK = new Token<ISubspaceLink>('SubspaceLink'); class SubspaceRelay implements ISubspaceLink { readonly frequency = 1420; } const Comms = defineModule({ name: 'Comms', providers: [provide(SUBSPACE_LINK, { useClass: SubspaceRelay })], }); const Meridian = defineModule({ name: 'Meridian', imports: [Comms] }); const getLink = (ship: Nexus) => { try { return ship.get(SUBSPACE_LINK); } catch (error) { return error; } }; await using ship = await Nexus.create(Meridian); const thin = getLink(ship); const line = isNexusError(thin) ? thin.message : null; // -> '[NEXUS_NOT_VISIBLE] token=SubspaceLink owners=Comms. https://nexus.js.org/errors/NEXUS_NOT_VISIBLE' console.log(line); await using fullShip = await Nexus.create(Meridian, { plugins: [errors()] }); const full = getLink(fullShip); const text = isNexusError(full) ? full.message.split('\n') : null; // -> ['[NEXUS_NOT_VISIBLE] SubspaceLink is provided in Comms, and the lookup module cannot see it.', ' Fix: export it along a path to the root module, or call get(SubspaceLink, { module: Comms }).'] 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 owners field names Comms. Then save the fix region below as fixed.ts and run npx tsx fixed.ts. It prints 1420.

Fix NEXUS_NOT_VISIBLE

NEXUS_NOT_VISIBLE is fixed by exporting the token along a path from its module to the root module, or by asking inside the owning module with ship.get(SUBSPACE_LINK, { module: Comms }). Modules covers encapsulation.

import { Nexus, Token, defineModule, provide } from '@nexusdi/core'; interface ISubspaceLink { readonly frequency: number; } const SUBSPACE_LINK = new Token<ISubspaceLink>('SubspaceLink'); class SubspaceRelay implements ISubspaceLink { readonly frequency = 1420; } const Comms = defineModule({ name: 'Comms', providers: [provide(SUBSPACE_LINK, { useClass: SubspaceRelay })], exports: [SUBSPACE_LINK], }); const Meridian = defineModule({ name: 'Meridian', imports: [Comms] }); await using ship = await Nexus.create(Meridian); const frequency = ship.get(SUBSPACE_LINK).frequency; // -> 1420 console.log(frequency);

Try it: delete the exports: [SUBSPACE_LINK], line from Comms in fixed.ts and run it again. ship.get(SUBSPACE_LINK) throws an uncaught NotVisibleError that starts with [NEXUS_NOT_VISIBLE] token=SubspaceLink owners=Comms.. Put the line back and the program prints 1420 again.

Fields of NotVisibleError

NotVisibleError carries these fields:

  • token: the display name of the token.
  • owners: the modules that provide it.
  • entry: the deps entry of resolve() or validate() this error is about, such as deps.v for the key v of an object, or null for get().