remix-run/remix · error · Error

Cannot specify both "only" and "exclude" options

Error message

Cannot specify both "only" and "exclude" options

What it means

createResourcesRoutes (the collection/statistics variant) accepts either an `only` or an `exclude` method filter, not both. Passing both truthy options throws this runtime validation error before any routes are built.

Source

Thrown at packages/fetch-router/src/lib/route-helpers/resources.ts:69

      exclude?: ResourcesMethod[]
      only?: never
    }
)

/**
 * Create a route map with standard CRUD routes for a resource collection.
 *
 * @param base The base route pattern to use for the resources
 * @param options Options to configure the resource routes
 * @returns The route map with CRUD routes
 */
export function createResourcesRoutes<base extends string, const options extends ResourcesOptions>(
  base: base | RoutePattern<base>,
  options?: options,
): BuildResourcesMap<base, options> {
  // Runtime validation
  if (options?.only && options?.exclude) {
    throw new Error('Cannot specify both "only" and "exclude" options')
  }

  // Resolve which methods to include
  let only: readonly ResourcesMethod[]
  if (options?.only) {
    only = options.only
  } else if (options?.exclude) {
    only = ResourcesMethods.filter((m) => !options.exclude!.includes(m))
  } else {
    only = ResourcesMethods
  }

  let param = options?.param ?? 'id'
  let indexName = options?.names?.index ?? 'index'
  let newName = options?.names?.new ?? 'new'
  let showName = options?.names?.show ?? 'show'
  let createName = options?.names?.create ?? 'create'
  let editName = options?.names?.edit ?? 'edit'

View on GitHub (pinned to 9696913134)

Solutions

  1. Remove one of the two options from the call
  2. Sanitize merged options so only one filter key is present
  3. Adopt a single filtering convention (only or exclude) across the codebase

Example fix

// before
createResourcesRoutes('/users', { ...defaults, only: ['index'] }) // defaults has exclude
// after
createResourcesRoutes('/users', { ...defaults, only: ['index'], exclude: undefined })
Defensive patterns

Strategy: validation

Validate before calling

if (options?.only && options?.exclude) throw new Error('only and exclude are mutually exclusive')

Prevention

When it happens

Trigger: createResourcesRoutes('/users', { only: ['index'], exclude: ['stats'] }) or merged option objects where both keys survive.

Common situations: Shared defaults objects that include exclude being combined with a call-site only (or vice versa); copy-pasting options between route helpers.

Related errors


AI-assisted analysis of remix-run/remix@9696913134 (2026-08-27). Data as JSON: /api/errors/e16e32fa104eecff. Report an issue: GitHub.