Disallow compiling with the emitDeclarationOnly TS compiler option enabled

Running the Angular compiler with declaration-only emission is dangerous because Angular does not yet support this mode as it relies on the Ivy compilation which does not run in this mode

In the best case, everything works fine as incidentally there’s no difference in the emitted type declarations (e.g. this is the case for TS files containing no Angular annotations or only @Injectable annotations).

In the worst case, compilation silently fails in that the compilation succeeds but the resulting type declarations are missing the Angular type information and are therefore incomplete. This happens for all components, directives and modules.

BREAKING CHANGE: The Angular compiler now produces an error when the the emitDeclarationOnly TS compiler option is enabled as this mode is not supported.

The option is set in the compilerOptions section of the tsconfig.json file:

"compilerOptions": {
"emitDeclarationOnly": true
}

To fix the error, you need to remove the emitDeclarationOnly option from the compilerOptions section of the tsconfig.json file or set it to false.

"compilerOptions": {
"emitDeclarationOnly": false
}

Exercise

Start running npm run build and observe the error.

Follow above instructions to fix the error.

Run the following command to check if the error is fixed:

Terminal window
npm run build

Powered by WebContainers
Files
Preparing Environment
  • Installing dependencies