Compilation Error: model 'stg_orders' depends on a node named 'raw_orders' which was not found"
Fixes the dbt compilation error where a model references a node dbt cannot see, by checking the ref name against real model files, defining missing sources, and re-running dbt compile. Use when dbt compile or dbt run fails with a 'depends on a node' error. Not for warehouse errors that happen after compilation succeeds.
TL;DR
dbt cannot find a node named raw_orders that stg_orders references. The usual causes are a typo in ref('raw_orders'), a source that was never defined in a _sources.yml file, or an upstream model that is disabled or excluded. Match the ref name to a real file, define the source, then recompile.
Error
Compilation Error: model 'stg_orders' depends on a node named 'raw_orders' which was not foundSteps
- Search your project for the file that should define the node: look for
models/**/raw_orders.sql. Expected: you find exactly one file, or you confirm it does not exist. - If
raw_ordersis a raw warehouse table rather than a dbt model, it must be declared as a source. Check that a_sources.ymlfile defines it and that the model callssource('raw', 'raw_orders')instead ofref('raw_orders'). Expected: the source appears indbt ls --resource-type source. - If the file exists, check for typos: the ref argument must match the file name without the
.sqlextension, exactly. Expected:ref('raw_orders')matchesraw_orders.sqlcharacter for character. - Check whether the upstream model is disabled (
enabled: falsein config) or excluded by your--select/--excludeflags. Expected:dbt ls --select raw_orderslists it. - Run
dbt compile --select stg_orders. Expected: compilation succeeds with no dependency error.
When to use
dbt compile,dbt run, ordbt testfails with "depends on a node named X which was not found".- You renamed a model or moved files between directories.
When not to use
- The error happens at warehouse runtime (a Database Error), not at compile time.
- The missing node is in an installed package (check
dbt depsand the package name in the ref).
Tool compatibility
- dbt Core 1.0 and later, all adapters.
dbt lsselectors work the same across versions.
Variant phrasings
Compilation Error: depends on a node named X which was not found or is disabled
The disabled variant: the file exists but enabled: false removes it from the graph.
source not found variants
When the call is source('a', 'b'), the fix is in _sources.yml, not in model files.
Why it happens
dbt builds a dependency graph from model files, seeds, snapshots, and declared sources before compiling any SQL. A ref() or source() pointing at something outside that graph is a hard error, because dbt cannot render the relation name.
Edge cases
- Two packages defining the same model name need the two-argument form:
ref('package_name', 'raw_orders'). - Model files under a directory excluded by
model-pathsare invisible to the graph. - Case sensitivity matters on some warehouses; keep file names lowercase.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst-otoltqjJw36yMjpOxvag