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_DEVTOOLS_UNREGISTERED
graph(ship) throws NEXUS_DEVTOOLS_UNREGISTERED when the container ship was created without devtools() in its plugins. graph() reads the compiled graph through the plugin’s context, and a container without the plugin gives it nothing to read. The call throws synchronously and bare, and graph() is the only call that raises this code.
Reproduce NEXUS_DEVTOOLS_UNREGISTERED
graph() throws NEXUS_DEVTOOLS_UNREGISTERED for a container that Nexus.create built with no plugins. @nexusdi/devtools writes this message itself, so it carries its full text and fix line with no text pack.
import { Nexus, Token, defineModule } from '@nexusdi/core';
import { isNexusError, provide } from '@nexusdi/core';
import { graph } from '@nexusdi/devtools';
interface IReactorCore {
readonly output: number;
}
const REACTOR = new Token<IReactorCore>('ReactorCore');
class FusionReactor implements IReactorCore {
readonly output = 1.21;
}
const Engineering = defineModule({
name: 'Engineering',
providers: [provide(REACTOR, { useClass: FusionReactor })],
});
await using ship = await Nexus.create(Engineering);
let code = '';
let message = '';
try {
graph(ship);
} catch (error) {
if (!isNexusError(error, 'NEXUS_DEVTOOLS_UNREGISTERED')) throw error;
code = error.code;
message = error.message;
}
const thrown = code; // -> 'NEXUS_DEVTOOLS_UNREGISTERED'
console.log(thrown);
const lines = message.split('\n'); // -> ['[NEXUS_DEVTOOLS_UNREGISTERED] graph() reads the container through devtools(), and this container was created without it.', " Fix: register devtools() in Nexus.create's plugins: Nexus.create(Root, { plugins: [devtools()] })."]
console.log(lines.join('\n'));Try it: run npm install @nexusdi/core@next and npm install -D @nexusdi/devtools@next, save the region as graph.ts and run npx tsx graph.ts. It prints the code, NEXUS_DEVTOOLS_UNREGISTERED, then the two-line message: [NEXUS_DEVTOOLS_UNREGISTERED] graph() reads the container through devtools(), and this container was created without it. and its Fix: line, Fix: register devtools() in Nexus.create's plugins: Nexus.create(Root, { plugins: [devtools()] }).
Fix NEXUS_DEVTOOLS_UNREGISTERED
NEXUS_DEVTOOLS_UNREGISTERED goes away when devtools() is in the plugins of the container that graph() reads. Register it in development, and leave production containers without it. To read a graph without building a container, call inspect(root), which needs no plugin.
import { Nexus, Token, defineModule, provide } from '@nexusdi/core';
import { devtools, graph } from '@nexusdi/devtools';
interface IReactorCore {
readonly output: number;
}
const REACTOR = new Token<IReactorCore>('ReactorCore');
class FusionReactor implements IReactorCore {
readonly output = 1.21;
}
const Engineering = defineModule({
name: 'Engineering',
providers: [provide(REACTOR, { useClass: FusionReactor })],
});
await using ship = await Nexus.create(Engineering, { plugins: [devtools()] });
const drawn = graph(ship).providers.filter((provider) => !provider.internal);
const tokens = drawn.map((provider) => provider.token); // -> ['ReactorCore']
console.log(tokens);Try it: save the region as fixed.ts and run npx tsx fixed.ts. It prints [ 'ReactorCore' ], the token of the one provider the module declares. The filter drops the internal providers that every graph lists. Change { plugins: [devtools()] } to { plugins: [] } and run it again. npx tsc accepts the file, and npx tsx fixed.ts throws an uncaught DevtoolsError and prints a stack trace headed DevtoolsError: [NEXUS_DEVTOOLS_UNREGISTERED] graph() reads the container through devtools(), and this container was created without it. Put devtools() back and the program prints [ 'ReactorCore' ] again.
Fields of DevtoolsError
code:'NEXUS_DEVTOOLS_UNREGISTERED'or'NEXUS_DEVTOOLS_GRAPH_INVALID'.path:nullforNEXUS_DEVTOOLS_UNREGISTERED. NEXUS_DEVTOOLS_GRAPH_INVALID sets it to the first field that failed.