The Angular Compiler requires TypeScript >=4.8.2 and <4.9.0 but 4.9.3 was found instead

avatar
Borislav Hadzhiev

Last updated: Apr 4, 2024
4 min

banner

# The Angular Compiler requires TypeScript >=4.8.2 and <4.9.0 but 4.9.3 was found instead

The error "Failed to initialize Angular compilation - the Angular Compiler requires TypeScript >=4.8.2 and <4.9.0 but 4.9.3 was found instead." occurs when your version of the Angular CLI does not support your version of TypeScript.

To solve the error, update your version of TypeScript to be in the supported range.

error failed to initialize angular compilation

shell
Error: Emit attempted before Angular Webpack plugin initialization. Error: Failed to initialize Angular compilation - the Angular Compiler requires TypeScript >=4.8.2 and <4.9.0 but 4.9.3 was found instead. ✖ Failed to compile.

# There are multiple ways to solve the error

You can solve the error by:

  1. Updating your version of TypeScript to a supported version.
  2. Disabling TypeScript version checking for your Angular project.

# Updating your version of TypeScript to the supported range

One way to solve the error is to update your version of TypeScript to one in the supported range.

The command you have to run will depend on your error message.

Assuming you got an error of "the Angular Compiler requires TypeScript >=4.8.2 and <4.9.0", then you have to install a TypeScript version that is:

  • >= 4.8.2
  • and is < 4.9.0

Open your terminal in your project's root directory (where your package.json) file is and run the following command.

Make sure to update the version numbers in the command based on your error message.
shell
npm install typescript@">=4.8.2 and <4.9.0" --save-dev

angular install correct typescript version

Your error message will contain the supported TypeScript versions for your version of the Angular CLI, so make sure to update the version numbers in the command.

If you get an error when installing a specific version of TypeScript, run the command with the --legacy-peer-deps option.

shell
npm install typescript@">=4.8.2 and <4.9.0" --save-dev --legacy-peer-deps

You can also uninstall typescript and then install the specific version from your error message.

shell
npm uninstall typescript npm install typescript@">=4.8.2 and <4.9.0" --save-dev

Once you update your TypeScript version to be in the supported range, you will be able to run ng serve --open without any issues.

shell
ng serve --open

# Checking your Angular CLI version

The version of TypeScript you have to install depends on your Angular CLI version.

shell
ng version

angular cli get version

You can view the Angular CLI TypeScript compatibility table to check which version of TypeScript you have to install depending on your version of the Angular CLI.

For example, my version of the Angular CLI is 15.0.2, so I would install version ~4.8.4 of TypeScript.

shell
npm install typescript@"~4.8.4" --save-dev

Alternatively, you can update the typescript development dependency in your package.json file.

package.json
{ "devDependencies": { "typescript": "~4.8.4" // ... rest } }

update typescript dependency in package json

Once you update your package.json file, you have to rerun npm install for the changes to take effect.

shell
npm install

Make sure to specify the correct version of TypeScript depending on your version of the Angular CLI.

You can view the Angular CLI to TypeScript compatibility table in this GitHub gist.

# Example for version 15.1.0

For example, if the ng version command returns a version of 15.1.0, then you can either run the following command

shell
npm install typescript@">=4.8.4 <5.0.0" --save-dev

Or you can update the TypeScript version in the devDependencies object in your package.json file.

package.json
{ "devDependencies": { "typescript": ">=4.8.4 <5.0.0" // ... rest } }

Once you update your package.json file, you have to rerun npm install for the changes to take effect.

shell
npm install

I've also written a detailed guide on how to check which version of TypeScript is installed.

# Example for version 14.2.0

If the ng version command returns a version of 14.2.0, then you have to install version >=4.6.4 <4.9.0 of TypeScript as shown in this table.

shell
npm install typescript@">=4.6.4 <4.9.0" --save-dev

Or you can update the TypeScript version in the devDependencies object in your package.json file.

package.json
{ "devDependencies": { "typescript": ">=4.6.4 <4.9.0" // ... rest } }

Once you update your package.json file, you have to rerun npm install for the changes to take effect.

shell
npm install

Alternatively, you can disable TypeScript version checking.

# Disable TypeScript version check

If the error persists, you can disable TypeScript version checking by editing your tsconfig.json file.

The tsconfig.json file should be located in the root directory of your Angular project, right next to your package.json file.

In the angularCompilerOptions object in your tsconfig.json file, set the disableTypeScriptVersionCheck property to true.

tsconfig.json
{ "compileOnSave": false, "compilerOptions": { // ... rest }, "angularCompilerOptions": { // ... rest "disableTypeScriptVersionCheck": true } }

disable typescript version check

When the disableTypeScriptVersionCheck option is set to true, the compiler doesn't look at the TypeScript version and doesn't report an error when an unsupported TypeScript version is installed.

In general, enabling this option is not recommended because you might encounter issues when using an unsupported TypeScript version.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.