ng build fails with TS1005 inside @types/babel__traverse
ERROR in node_modules/@types/babel__traverse/index.d.tsShort answer
The compiler could not parse a declaration file in node_modules, which almost always means the @types package was written for a newer TypeScript than yours. Upgrade TypeScript to the range your Angular version supports, or pin the @types package to an older release.
Fix it fast
1Find out which cause you have
Compare the TypeScript version you run with the version of the failing @types package.
npx tsc -v npm ls typescript @types/babel__traverse2Match what you see, then jump to its fix
What does the error look like?
ERROR in node_modules/@types/babel__traverse/index.d.tserror TS1005: ']' expected.
Cause 1 of 2
TypeScript is older than the declarations need
1Check
DefinitelyTyped tests packages only on TypeScript versions less than 2 years old, so a package can use syntax an old compiler cannot parse. Compare tsc -v with the Angular version table.
npx ng version2Fix
Move TypeScript to the range Angular lists for your version. Angular 20.2 and 20.3 list >=5.8.0 <6.0.0.
npm install --save-dev typescript@">=5.8.0 <6.0.0"3Verify
Rebuild.
npx ng buildConfirmed by angular.dev
Cause 2 of 2
You cannot upgrade TypeScript right now
1Check
Older releases of an @types package stay available, so you can install one from the time your TypeScript was current.
npm view @types/babel__traverse versions --json2Fix
Install an older release of the @types package, and pin it exactly so npm does not float it forward.
npm install --save-dev --save-exact @types/babel__traverse@<older-version>3Verify
Rebuild after the install.
npx ng buildConfirmed by github.com
How do I stop it coming back?
- Upgrade Angular and TypeScript together and keep them inside the documented range.
- Commit the lockfile so a fresh install does not pull a newer @types package.
- Read the Angular version table before you update TypeScript on its own.
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
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
Angular build fails with TS2707 or "has no exported member" after installing a library
Module '"@angular/core"' has no exported member
These errors mean a library was compiled by a newer Angular than your app uses.
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