Error: main.ts is missing from the TypeScript compilation.

This is one of those blog posts where I want to provide a reference to my future self and anyone else who encounters this problem.

The problem presents itself when trying to build (via ng build or ng serve) your Angular application and you see the following error.

ERROR in ./src/main.ts
Module build failed: Error: <path\to\>src\main.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the ‘files’ or ‘include’ property.

Likely, you will also see a similar error for polyfills.ts. If this is the case, check to see if your app is located on a path which is a symlink.

Angular compiler doesn’t like symlinks, at least on Windows. I believe it has something to do with Node.js module resolution. Luckily, there is a solution which doesn’t involve changing paths.

You can add --preserve-symlinks to your ng build command, but since that option isn’t available for the serve command, your best bet is to add it to your angular.json file.

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

I ran into this lately when a number of our CI builds started using a symlink somewhere higher in the build path and that caused a number of mysterious failures.

Hopefully this helps you avoid digging through GitHub issues and Stackoverflow answers.

There are no comments available on this site. If you want to respond then you can write your own blog article and send me the link via twitter. If there is an issue with this article or the site in general, you can open an issue on Github