Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Angular build fails with TS2707 or "has no exported member" after installing a library

Errorerror TS2707: Generic type 'ɵɵDirectiveDeclaration' requires between 6 and 8 type arguments.

Short answer

These errors mean a library was compiled by a newer Angular than your app uses. Angular requires the app's version to be the same or greater than that of its libraries. Install the library release for your Angular major, or update core and CLI with ng update, then reinstall.

  • Applies to Angular CLI 21, Node.js 24, npm 11, TypeScript 5.9
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Compare the Angular major of your core package with the library that fails. They are usually different.

    npm ls @angular/core @angular/material @angular/cdk --depth=0
  2. 2Match what you see, then jump to its fix

    1. 1Errors point into node_modules/@angular/material or another library's .d.ts files, not your own codeThe library is newer than the Angular in your appFix
    2. 2npm ls shows @angular/core and @angular/cli with different major numbersCore, CLI and the compiler are on different majorsFix
    3. 3node -v or tsc -v falls outside the row for your Angular major in the compatibility tableTypeScript or Node.js is outside the range for your AngularFix

What does the error look like?

  • error TS2707: Generic type 'ɵɵDirectiveDeclaration' requires between 6 and 8 type arguments.
  • Module '"@angular/core"' has no exported member

Cause 1 of 3

The library is newer than the Angular in your app

1Check

A library is published in partial compilation form and is finished by your app's own Angular build. Angular's rule is that the app's version must be the same or greater than the version used to build any library it depends on. A newer Material against an older core breaks that rule.

npm ls @angular/core --depth=0
grep -n "@angular/" package.json

2Fix

Install the library at the same major as your core, or move the whole app forward one major at a time.

npm install @angular/material@<your-core-major> @angular/cdk@<your-core-major>
# or move the app up:
npx ng update @angular/core@<next-major> @angular/cli@<next-major>

3Verify

A fresh build compiles with no TS2707.

npx ng build

Confirmed by angular.dev

Did this fix it?

Cause 2 of 3

Core, CLI and the compiler are on different majors

1Check

A half-finished update leaves some @angular packages behind. Application builds need the compiler and runtime to match.

npm ls @angular/core @angular/cli @angular/compiler-cli --depth=0

2Fix

Update the packages together in one ng update call so the CLI picks matching releases.

npx ng update @angular/core@<major> @angular/cli@<major>

3Verify

All three packages show one major.

npm ls @angular/core @angular/cli @angular/compiler-cli --depth=0

Confirmed by angular.dev

Did this fix it?

Cause 3 of 3

TypeScript or Node.js is outside the range for your Angular

1Check

Each Angular major lists the Node.js, TypeScript and RxJS versions it requires on the compatibility page.

node -v
npx tsc -v

2Fix

Install the TypeScript and Node.js versions listed for your Angular major.

npm install --save-dev typescript@"<range-from-table>"

3Verify

Build again after a clean install.

rm -rf node_modules
npm ci
npx ng build

Confirmed by angular.dev

Did this fix it?

How do I stop it coming back?

  • Keep Angular, CDK and Material on the same major and update them in one command.
  • Commit package-lock.json and install with npm ci in CI so everyone builds the same tree.
  • Never run a bare npm install @angular/material@latest in an app that is a major behind.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

cdk synth says --app is required

--app is required either in command-line, in cdk.json or in ~/.cdk.json

The CDK CLI needs a command that runs your app and finds it in three places: the --app option, cdk.json in the project folder, or cdk.json in your home folder.

3 causes, each with a fix

Back end

Mocha or Node cannot find ts-node/register

Error: Cannot find module 'ts-node/register'

Node resolves ts-node/register from your project's node_modules, so the package must be installed there, next to typescript.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.