Angular build fails with TS2707 or "has no exported member" after installing a library
error 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.
Fix it fast
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=02Match what you see, then jump to its fix
- 1
Errors 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
npm ls shows @angular/core and @angular/cli with different major numbersCore, CLI and the compiler are on different majorsFix - 3
node -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
- 1
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.json2Fix
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 buildConfirmed by angular.dev
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=02Fix
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=0Confirmed by angular.dev
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 -v2Fix
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 buildConfirmed by angular.dev
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Back end
ng update stops on peer dependency errors when moving to a much newer Angular
Peer dependency warnings when installing dependencies means that those dependencies might not work correctly together.
Angular supports updates one major version at a time, so a jump such as 8 to 13 in one go leaves packages whose peer ranges do not match.
3 causes, each with a fixBack end
TypeScript cannot find '@angular/platform-browser' in an Angular project
Cannot find module '@angular/platform-browser' or its corresponding type declarations.
TS2307 means TypeScript could not turn the import into a file.
3 causes, each with a fixBack 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 fixBack end
TypeScript cannot find module '@nestjs/core' or its type declarations
error TS2307: Cannot find module '@nestjs/common' or its corresponding type declarations.
TS2307 means TypeScript searched node_modules and found neither the package nor its types.
3 causes, each with a fixBack 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 fixBack end
TypeError: Class constructor cannot be invoked without 'new' in compiled TypeScript
TypeError: Class constructors cannot be invoked without 'new'
Node.js throws this when a native class is called like a plain function.
2 causes, each with a fix