{"id":"20643faf7bfb36df","repo":"fastify/fastify","slug":"fst-err-dec-missing-dependency","errorCode":"FST_ERR_DEC_MISSING_DEPENDENCY","errorMessage":"The decorator is missing dependency '%s'.","messagePattern":"The decorator is missing dependency '(.+?)'\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/decorate.js","lineNumber":125,"sourceCode":"\nfunction checkReplyExistence (name) {\n  if (name && hasKey(this[kReply], name)) return true\n  if (name && hasInstanceProperty(this[kReply], name)) return true\n  return checkExistence(this[kReply].prototype, name)\n}\n\nfunction checkDependencies (instance, name, deps) {\n  if (deps === undefined || deps === null) {\n    return\n  }\n\n  if (!Array.isArray(deps)) {\n    throw new FST_ERR_DEC_DEPENDENCY_INVALID_TYPE(name)\n  }\n\n  for (let i = 0; i !== deps.length; ++i) {\n    if (!checkExistence(instance, deps[i])) {\n      throw new FST_ERR_DEC_MISSING_DEPENDENCY(deps[i])\n    }\n  }\n}\n\nfunction decorateReply (name, fn, dependencies) {\n  assertNotStarted(this, name)\n  checkReferenceType(name, fn)\n  decorateConstructor(this[kReply], name, fn, dependencies)\n  return this\n}\n\nfunction decorateRequest (name, fn, dependencies) {\n  assertNotStarted(this, name)\n  checkReferenceType(name, fn)\n  decorateConstructor(this[kRequest], name, fn, dependencies)\n  return this\n}\n","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/fastify/fastify/blob/7299a57d3fdce7da49f2c6d19ba08dc673e53f22/lib/decorate.js#L107-L143","documentation":"Thrown by checkDependencies() (decorate.js:124) when a name listed in the dependencies array does not exist on the instance (checked via checkExistence). It enforces ordering: if decorator 'cart' depends on 'session', 'session' must already be registered before 'cart' is added.","triggerScenarios":"Calling fastify.decorate('cart', fn, ['session']) before 'session' has been registered; a typo in a dependency name; dependency declared but its providing plugin not yet registered in the boot chain.","commonSituations":"Plugin load order issues where the consumer registers the dependent decorator before the dependency; refactoring that splits decorators into plugins without updating order; optional dependencies that aren't always loaded.","solutions":["Register the dependency decorator first: app.decorate('session', ...); then app.decorate('cart', ..., ['session']).","Inside plugins, use avvio's boot ordering: register the dependency-providing plugin before the dependent plugin in the fastify.register chain.","Verify the dependency name spelling matches exactly (case-sensitive).","If the dependency is optional, drop it from the array and check existence at runtime via hasDecorator."],"exampleFix":"// before\napp.decorate('cart', getCart, ['session']) // 'session' missing => throws\n\n// after\napp.decorate('session', getSession)\napp.decorate('cart', getCart, ['session'])","handlingStrategy":"validation","validationCode":"function decorateWithDeps(app, name, value, deps) {\n  const missing = (deps || []).filter(d => !app.hasDecorator(d))\n  if (missing.length) {\n    throw new Error('Missing decorators: ' + missing.join(', '))\n  }\n  app.decorate(name, value, deps)\n}","typeGuard":"function depsAvailable(app, deps) {\n  return (deps || []).every(d => app.hasDecorator(d))\n}","tryCatchPattern":"try {\n  app.decorate('cart', getCart, ['session'])\n} catch (err) {\n  if (err.code === 'FST_ERR_DEC_MISSING_DEPENDENCY') {\n    app.decorate('session', getSession)\n    app.decorate('cart', getCart, ['session'])\n  } else throw err\n}","preventionTips":["Register dependency decorators before dependent ones in the boot chain.","Use app.hasDecorator(d) to validate before calling decorate when deps are optional.","Keep a topological ordering of decorator registration in your bootstrap code."],"tags":["decorators","dependencies","ordering","plugins"],"analyzedSha":"7299a57d3fdce7da49f2c6d19ba08dc673e53f22","analyzedAt":"2026-08-03T17:43:01.300Z","schemaVersion":2}