NG0301 Angular Origin: On your device Last updated 15 Oct 2026

Angular: NG0301: Export of name 'x' not found! (template variable #x="exportAs")

A template variable asks for a directive by exportAs name, but no directive with that export is on the element at runtime.

Exact message you may see NG0301: Export of nameExport of name 'ngForm' not found!Export of name 'matMenu' not found!
Seen on: Angular TypeScript

Meaning

Same cause as NG8003 but raised at runtime (JIT or tests). The directive's module is not loaded or does not apply to this element. Check the exportAs name and the imports of the component under test.

Common causes

  • Module that provides the directive is not imported (often in a unit test's TestBed)
  • Wrong exportAs string
  • Directive selector does not match the element
  • Lazy-loaded module not loaded yet
  • Standalone directive missing from imports

⚡ Quick fix

  1. Import the directive or module in the component and in the TestBed
  2. Verify the exportAs name in the docs
  3. Check the element matches the directive selector

Detailed fix by platform

Angular

  1. TestBed.configureTestingModule({ imports: [FormsModule, MatMenuModule] }) for components that use exportAs references

How to diagnose

  1. Name — Which exportAs?
  2. Imports — In the component and the test?
  3. Element — Selector matches?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: On your device. Errors that are often confused with or caused by this one (click to open):

Component is not resolved: templateUrl — Angular tests: Component 'X' is not resolved: templateUrl: ./x.component.html — Did you run and wait for 'resolveComponentResources()'? (Angular)Component is not reso…NG02200 — Angular: NG02200: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays (Angular)NG02200NG8001 — Angular: NG8001: 'app-item' is not a known element — verify that it is included in the component's imports (Angular)NG8001NG8002 — Angular: NG8002: Can't bind to 'ngModel' since it isn't a known property of 'input' (Angular)NG8002NG8003 — Angular: NG8003: No directive found with exportAs 'ngForm' (template reference variable) (Angular)NG8003NG8004 — Angular: NG8004: No pipe found with name 'async' / 'date' / 'translate' — pipe not imported (Angular)NG8004NG8103 — Angular: NG8103: The *ngIf directive was used, but neither the NgIf directive nor the CommonModule was imported (Angular)NG8103NG8113 — Angular: NG8113: NgIf is not used within the template of AppComponent — unused standalone import (Angular)NG8113NG0301

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.