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.
NG0301: Export of nameExport of name 'ngForm' not found!Export of name 'matMenu' not found! 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
exportAsstring - Directive selector does not match the element
- Lazy-loaded module not loaded yet
- Standalone directive missing from
imports
⚡ Quick fix
- Import the directive or module in the component and in the TestBed
- Verify the exportAs name in the docs
- Check the element matches the directive selector
Detailed fix by platform
Angular
TestBed.configureTestingModule({ imports: [FormsModule, MatMenuModule] })for components that use exportAs references
How to diagnose
- Name — Which exportAs?
- Imports — In the component and the test?
- 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:
Similar errors
- Component is not resolved: templateUrl Angular tests: Component 'X' is not resolved: templateUrl: ./x.component.html — Did you run and wait for 'resolveComponentResources()'?
- NG02200 Angular: NG02200: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays
- NG8001 Angular: NG8001: 'app-item' is not a known element — verify that it is included in the component's imports
Most viewed in Angular
- NullInjectorError Angular: NullInjectorError: No provider for X!
- NG0100 Angular: NG0100: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked
- NullInjectorError: No provider for HttpClient! Angular: NullInjectorError: No provider for HttpClient! — provideHttpClient() missing
Other ways to find it
Where this error sits
Origin: On your device. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 15 Oct 2026