Last updated: Apr 4, 2024
Reading time·4 min
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: 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.
You can solve the error by:
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
< 4.9.0
Open your terminal in your project's root directory (where your package.json
)
file is and run the following command.
npm install typescript@">=4.8.2 and <4.9.0" --save-dev
If you get an error when installing a specific version of TypeScript, run the
command with the --legacy-peer-deps
option.
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.
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.
ng serve --open
The version of TypeScript you have to install depends on your Angular CLI version.
ng 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.
npm install typescript@"~4.8.4" --save-dev
Alternatively, you can update the typescript
development dependency in your
package.json
file.
{ "devDependencies": { "typescript": "~4.8.4" // ... rest } }
Once you update your package.json
file, you have to rerun npm install
for
the changes to take effect.
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.
For example, if the ng version
command returns a version of 15.1.0
, then you
can either run the following command
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.
{ "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.
npm install
I've also written a detailed guide on how to check which version of TypeScript is installed.
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.
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.
{ "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.
npm install
Alternatively, you can disable TypeScript version checking.
If the error persists, you can disable TypeScript version checking by editing your tsconfig.json file.
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
.
{ "compileOnSave": false, "compilerOptions": { // ... rest }, "angularCompilerOptions": { // ... rest "disableTypeScriptVersionCheck": true } }
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.
You can learn more about the related topics by checking out the following tutorials: