remix-run/remix · error · Error
Cannot specify both "only" and "exclude" options
Error message
Cannot specify both "only" and "exclude" options
What it means
createResourceRoutes accepts either an `only` list (restrict to specific methods) or an `exclude` list (remove specific methods), but not both — they are contradictory filters. This runtime check rejects the combination immediately.
Source
Thrown at packages/fetch-router/src/lib/route-helpers/resource.ts:62
exclude?: ResourceMethod[]
only?: never
}
)
/**
* Create a route map with standard CRUD routes for a singleton resource.
*
* @param base The base route pattern to use for the resource
* @param options Options to configure the resource routes
* @returns The route map with CRUD routes
*/
export function createResourceRoutes<base extends string, const options extends ResourceOptions>(
base: base | RoutePattern<base>,
options?: options,
): BuildResourceMap<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 ResourceMethod[]
if (options?.only) {
only = options.only
} else if (options?.exclude) {
only = ResourceMethods.filter((m) => !options.exclude!.includes(m))
} else {
only = ResourceMethods
}
let newName = options?.names?.new ?? 'new'
let showName = options?.names?.show ?? 'show'
let createName = options?.names?.create ?? 'create'
let editName = options?.names?.edit ?? 'edit'
let updateName = options?.names?.update ?? 'update'
let destroyName = options?.names?.destroy ?? 'destroy'View on GitHub (pinned to 9696913134)
Solutions
- Keep exactly one of only or exclude
- When merging configs, delete the other key: { ...opts, exclude: undefined }
- Prefer exclude for deny-lists and only for allow-lists — pick one strategy project-wide
Example fix
// before
createResourceRoutes('/posts', { only: ['list','show'], exclude: ['destroy'] })
// after
createResourceRoutes('/posts', { only: ['list','show'] }) Defensive patterns
Strategy: validation
Validate before calling
if (options?.only && options?.exclude) throw new Error('only and exclude are mutually exclusive') Prevention
- Pick one filtering strategy (only vs exclude) project-wide
- Strip the conflicting key when merging option presets
When it happens
Trigger: createResourceRoutes('/posts', { only: ['list'], exclude: ['destroy'] }) — any call passing both options truthy.
Common situations: Merging option objects from config presets where a default only/exclude collides with a call-site override.
Related errors
- Cannot specify both "only" and "exclude" options
- hmr must be provided
- hmr requires watch mode
- mounts values must be relative to rootDir. Received "${fileR
- mounts keys must be URL pathnames without query strings, fra
AI-assisted analysis of remix-run/remix@9696913134 (2026-08-27).
Data as JSON: /api/errors/ad55f8d036c35b9c.
Report an issue: GitHub.