remix-run/remix · error · Error

Cannot install context property {formattedProperty} because

Error message

Cannot install context property {formattedProperty} because another context key already uses it.

What it means

Property names on RequestContext are globally unique: two different context keys cannot install the same property name. This error fires when key B tries to use a property name already installed by a different key A.

Source

Thrown at packages/fetch-router/src/lib/request-context.ts:315

    }

    if (property.length === 0) {
      throw new Error('Cannot install an empty context property name.')
    }

    let formattedProperty = JSON.stringify(property)

    let existingProperty = this.#contextPropertyKeys.get(key)
    if (existingProperty != null && existingProperty !== property) {
      throw new Error(
        `Cannot install context property ${formattedProperty} because this context key already uses ${JSON.stringify(existingProperty)}.`,
      )
    }

    let existingKey = this.#contextProperties.get(property)
    if (existingKey != null) {
      if (existingKey !== key) {
        throw new Error(
          `Cannot install context property ${formattedProperty} because another context key already uses it.`,
        )
      }

      return
    }

    if (property in this) {
      throw new Error(
        `Cannot install context property ${formattedProperty} because it already exists on RequestContext.`,
      )
    }

    this.#contextProperties.set(property, key)
    this.#contextPropertyKeys.set(key, property)

    Object.defineProperty(this, property, {
      get: () => this.get(key),

View on GitHub (pinned to 9696913134)

Solutions

  1. Prefix property names per feature: 'authUser' vs 'currentUser'
  2. Read the existing property via its owning key instead of installing a second one
  3. Centralize key+property registration in one module

Example fix

// before
ctx.set(authKey, a, { property: 'user' })
ctx.set(profileKey, p, { property: 'user' })
// after
ctx.set(authKey, a, { property: 'authUser' })
ctx.set(profileKey, p, { property: 'profileUser' })
Defensive patterns

Strategy: validation

Validate before calling

const usedBy = contextProperties.get(property)
if (usedBy != null && usedBy !== key) throw new Error('property already in use')

Prevention

When it happens

Trigger: ctx.set(userKey, u, { property: 'user' }) in one middleware and ctx.set(authKey, a, { property: 'user' }) in another.

Common situations: Multiple packages or middleware independently attaching a generic name like 'user' or 'session'; merging middleware from different authors.

Related errors


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