Skip to Content
TelamonJS

Troubleshooting

Two copies of a peer dependency, "No QueryClient set", consuming the packages via link:, NestJS guard exceptions across package instances, and the Zustand getSnapshot loop

Most hard-to-read errors in a TelamonJS app have one of two causes: two copies of a peer dependency in the same process, or a dynamic Zustand selector inside a custom hook. This page covers both. Problems specific to one feature stay on that feature's page: see the Troubleshooting sections of Auth and Provider Setup.


Two copies of a peer dependency

@tanstack/react-query, react, next-intl and, on the API side, @nestjs/common are peer dependencies of the TelamonJS packages. When you install a package from the registry, its peers resolve to the app's own copy, so there is one instance of each.

That stops being true when the package is linked instead of installed (link: or file: in package.json, pnpm link, or a local checkout outside the app's workspace). The linked package then resolves its peers (and its own dependencies, such as lucide-react) from its own node_modules, and the process ends up with two copies of the same module. Anything that relies on module identity breaks:

PeerWhat breaks
@tanstack/react-queryReact context: No QueryClient set, or query.isFetched is not a function
lucide-reactTypes: a LucideIcon from the app is not assignable to the library's
@nestjs/commoninstanceof: a guard's UnauthorizedException becomes a 500

The fix in every case is to end up with a single copy. The sections below give the specific setting for each peer.


"No QueryClient set"

Symptom: React Query hooks throw No QueryClient set, use QueryClientProvider to set one, even though a provider is mounted.

Cause: two instances of the react-query module. The provider registers its context on one instance and the hook reads the other.

Fix:

  1. Import QueryClient, QueryCache, MutationCache, useQuery and the rest directly from @tanstack/react-query. @telamonjs/ui deliberately does not re-export them: a re-export creates a second instance under optimizePackageImports.

  2. Let Next.js optimize the barrel instead of using deep imports:

    next.config.js
    experimental: {
      optimizePackageImports: ['@telamonjs/ui', 'lucide-react'],
    }

    Apps generated by the CLI already ship this setting.

  3. Create one QueryClient per app (in useState, in a client component) and pass it both to your own QueryClientProvider and to AppProviders in config.queryClient. The complete providers file is in Provider Setup.

next-intl follows the same rule as react-query: it is not re-exported either, so import useTranslations and friends from next-intl directly.

When the app's client comes from another copy

With a linked @telamonjs/ui, the app's QueryClient can come from a different copy (sometimes a different version) of react-query. A foreign client breaks the library's observers (query.isFetched is not a function), so AppProviders ignores it, logs a development-only warning and falls back to its internal client:

[telamonjs] config.queryClient comes from another @tanstack/react-query copy (link mode?) — using the internal client.

This is why the providers file keeps its own QueryClientProvider around AppProviders, with the same client: in that situation the outer provider is the one serving the app's hooks. With the package installed from the registry there is a single copy, and AppProviders uses the app's client for the whole tree.

The warning also explains a confusing difference between environments. If the app passes its client only to an outer QueryClientProvider and not to AppProviders, its global onError handlers work in linked development (two copies, two clients) and silently stop working with the published package (one copy, where the client AppProviders creates shadows the app's).


Linking a local TelamonJS checkout into an app is useful to test a change before it is published. Keep these rules in mind:

  • Build first. The packages resolve types and code from dist/. Run pnpm build in the TelamonJS checkout before starting the app, and keep pnpm dev running in the package you are changing. Without a build the app fails with Cannot find module '@telamonjs/…', which is the missing build, not a broken import.

  • Prefer an injected file: dependency over link:. With a plain link:, @telamonjs/ui resolves its peers (next-intl, @tanstack/react-query, next-auth, next-themes) from the checkout's own node_modules, so the app ends up with two copies and errors like "context from NextIntlClientProvider was not found". With pnpm, point the app at the checkout with file: and mark it injected, so the package is copied into the app and resolves the app's peers:

    package.json
    {
      "dependencies": { "@telamonjs/ui": "file:../telamonjs/packages/ui" },
      "dependenciesMeta": { "@telamonjs/ui": { "injected": true } },
      "pnpm": { "overrides": { "@telamonjs/logger": "link:../telamonjs/packages/logger" } }
    }

    telamonjs link writes exactly these entries and telamonjs unlink removes them (see CLI › link / unlink).

    Re-run pnpm install after rebuilding the package so the injected copy picks up the new dist/. The @telamonjs/logger override is required, not optional: in the checkout, @telamonjs/ui declares the logger as workspace:^, which only resolves through the override. Run telamonjs unlink before committing or building against the registry; monorepos generated by the CLI do it in a pre-commit hook.

  • One copy of each peer. Expect the two-copy problems above. Keep the optimizePackageImports setting, pass the app's client to AppProviders, and keep the outer QueryClientProvider.

  • Menu icons as strings. Pass icon: 'Receipt', not the Lucide component: with two copies of lucide-react, the app's LucideIcon is a different type from the library's and type-check fails. Strings are resolved through setIconResolver() and work the same in both setups (see Icon Resolver).

  • Switch back before shipping. None of the workarounds on this page are needed with a registry install, and some of them (the outer provider) are harmless there. Test the final version against the published package.


NestJS guard exceptions across package instances

Symptom: a request with a missing or invalid token (or without the permission) gets a 500 instead of a 401 (or 403), but only in development.

Cause: with @telamonjs/auth or @telamonjs/permissions linked, the guard and the host API resolve @nestjs/common from different node_modules, so there are two UnauthorizedException (and ForbiddenException) classes. Nest's exception filters use instanceof, so the exception thrown by the package's copy is not recognized by the host's filters and surfaces as a generic 500.

Fix: with a registry install there is nothing to do: @nestjs/common is a peer dependency and resolves to the host's single copy. While the package is linked, pass createException to both guards so they throw the host's own classes. Both options share one signature, so one function serves both:

src/common/guards/http-exception.ts
import { ForbiddenException, UnauthorizedException } from '@nestjs/common' // the host's copy

export const createException = (status: 401 | 403, message: string) =>
  status === 401 ? new UnauthorizedException(message) : new ForbiddenException(message)
export const JwtAuthGuard = createJwtAuthGuard({ createException })
export const PermissionsGuard = createPermissionsGuard({ createException })

Without the option, the guards keep throwing the package's own Nest exceptions.

@telamonjs/queue/nestjs also takes @nestjs/common as a peer and has no such option: while it is linked, catch its exceptions in the host and re-throw them with the host's classes (match on e.name, since instanceof is what fails).


Zustand: "The result of getSnapshot should be cached"

Symptom: React logs The result of getSnapshot should be cached to avoid an infinite loop, and the component re-renders until React gives up. The stack trace goes through useSyncExternalStore and Zustand's useStore.

Cause: a dynamic selector (one that depends on a hook parameter, such as state => state.forms[formId]) inside a custom hook. The selector is recreated on every render. Wrapping it in useCallback, useMemo or a ref does not fix it.

Fix: subscribe to the store and select locally:

// ❌ inside a custom hook
const data = useFormStore(state => state.forms[formId])

// ✅
const formState = useFormStore()
const data = formState.forms[formId]

Static selectors (state => state.items) are fine. The full explanation, the trade-offs and when to reach for useShallow are in Zustand Selector Pattern.

On this page