After upgrading an existing project from Angular 14 to 15 yesterday, the project would no longer run (with ng serve). The error message was rather confusing:

main.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property

Well, the file was obviously there and present in tsconfig(.app).json. Spent half a day googling and upgrading and downgrading packages to try and fix it to no avail. Even spun up a blank new Angular project to compare the contents of the json files to see if I missed something, but nothing fixed it.

Finally this morning I stumbled upon this discussion on the GitHub of the angular cli project from someone that had the same experience, only to fail to reproduce it on another machine and with the developers. Even after dismissing it being an issue with angular-cli, he was nice enough to share his fix. Sure enough, it worked for me as well.

The problem was not with the Angular version upgrade at all. I had simultaneously moved the project directory to my new Windows 11 Dev Drive to increase build performance, and at the old location created a symlink towards the new directory.

Turns out: Angular CLI (cq. Node) does not like symlinks on Windows.

Put "preserveSymlinks": true in your angular.json under architect/build/options, like this:

"architect": {
  "build": {
    "builder": "@angular-devkit/build-angular:browser",
    "options": {
      ...
      "preserveSymlinks": true,
      ...

Many thanks to Colin Bate who blogged about this and posted the solution.

Shiftkey Avatar

Published by

Plaats een reactie