0

I'm constantly getting this error:

- Generating browser application bundles (phase: setup)...
An error occurred during the build:
Error: The Angular Compiler requires TypeScript >=4.2.3 and <4.4.0 but 4.5.4 was found instead.
    at checkVersion (C:\..path..\Client\node_modules\@angular\compiler-cli\src\typescript_support.js:65:19)
    at Object.verifySupportedTypeScriptVersion (C:\..path..\Client\node_modules\@angular\compiler-cli\src\typescript_support.js:70:9)
    at new NgtscProgram (C:\..path..\Client\node_modules\@angular\compiler-cli\src\ngtsc\program.js:47:38)
    at AngularWebpackPlugin.updateAotProgram (C:\..path..\Client\node_modules\@ngtools\webpack\src\ivy\plugin.js:310:32)
    at C:\..path..\Client\node_modules\@ngtools\webpack\src\ivy\plugin.js:187:24
    at Hook.eval [as call] (eval at create (C:\..path..\Client\node_modules\tapable\lib\HookCodeFactory.js:19:10), <anonymous>:28:1)
    at Hook.CALL_DELEGATE [as _call] (C:\..path..\Client\node_modules\tapable\lib\Hook.js:14:14)
    at Compiler.newCompilation (C:\..path..\Client\node_modules\webpack\lib\Compiler.js:1043:30)
    at C:\..path..\Client\node_modules\webpack\lib\Compiler.js:1088:29
    at Hook.eval [as callAsync] (eval at create (C:\..path..\Client\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:22:1)
An unhandled exception occurred: The Angular Compiler requires TypeScript >=4.2.3 and <4.4.0 but 4.5.4 was found instead.
See "C:\Users\...\AppData\Local\Temp\ng-aVWIPB\angular-errors.log" for further details.

In package.json I have

"typescript": "^4.3.2"

I removed all files under node_modules, ran npm install. It did not resolve the issue. uninstalled typescript and then again installed typescript specific version by running command:

npm install typescript@4.3.2 

Then ran npm update. Still getting same error on running ng build.

James Z
  • 12,209
  • 10
  • 24
  • 44
SilverFish
  • 1,014
  • 6
  • 28
  • 65

1 Answers1

0

You have a higher level TypeScript version than is accepted: run npm uninstall typescript@4.5.4

viperguynaz
  • 12,044
  • 4
  • 30
  • 41
  • There's no reference for typescript 4.5.4 in my code. I still ran uninstall command for it as you suggested. Than ran tsc -v, which gave Version 4.3.2. But when I do a prod build using: ng build --configuration production --output-hashing none. Same error reappears – SilverFish Jan 04 '22 at 18:40
  • See your error message: `The Angular Compiler requires TypeScript >=4.2.3 and <4.4.0 but 4.5.4 was found instead.`. `^4.3.2` tells the complier to use anything from the specified version (including prerelease) will be supported up to, but not including, the next major version (or its prereleases). 4.5.4 will satisfy ^4.3.2, while 4.2.2 and 5.0.0-beta will not. – viperguynaz Jan 05 '22 at 22:51
  • another option is to make the typescript version fixed: use `"typescript": "4.3.2"` – viperguynaz Jan 11 '22 at 18:31