Solvedangular AOT on case insensitive file systems fails

I'm submitting a ... (check one with "x")

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior
When i run compilation with AOT enabled it fails with following error:

ERROR in Error encountered resolving symbol values statically. Calling function 'ɵmakeDecorator', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol Injectable in f:/git/universal-demo/node_modules/@angular/core/core.d.ts, resolving symbol BaseAnimatedComponent in f:/git/universal-demo/app/misc/baseAnimatedComponent.ts, resolving symbol BaseAnimatedComponent in f:/git/universal-demo/app/misc/baseAnimatedComponent.ts

ERROR in Error encountered resolving symbol values statically. Calling function 'ɵmakeDecorator', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol Component in f:/git/universal-demo/node_modules/@angular/core/core.d.ts, resolving symbol NotFoundComponent in f:/git/universal-demo/app/pages/notFound/notFound.component.ts, resolving symbol NotFoundComponent in f:/git/universal-demo/app/pages/notFound/notFound.component.ts

Expected behavior
AOT should work.

Minimal reproduction of the problem with instructions
Here are two branches which illustrates both of mentioned errors.

https://github.com/kukjevov/ng-universal-demo/tree/emakeerror
Branch: emakeerror
run npm install
then npm run build:aot

https://github.com/kukjevov/ng-universal-demo/tree/emakeerror2
Branch: emakeerror2
run npm install
then npm run build:aot

Please can somebody at least look at this? It is making impossible to use AOT.

Please tell us about your environment:
Windows 10, VSCode

  • Angular version: 4.0.1

  • Browser: [all]

  • Language: [TypeScript 2.2.1]

  • Node (for AoT issues): node --version = v6.9.4

20 Answers

✔️Accepted Answer

A workaround that is worked for me, is add inside the file tsconfig.app.json a path "@angular/": ["../node_modules/@angular/"]

"compilerOptions": {
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "lib": [
      "es2016",
      "dom"
    ],
    "outDir": "../out-tsc/app",
    "module": "es2015",
    "baseUrl": "",
    "types": [],
      "paths": {
      "@angular/*": ["../node_modules/@angular/*"] 
    }
  }

Other Answers:

I was having the exact same issue, and after spending 2 days in the devtools, I came with this patch:

import { CompilerHost } from '@angular/compiler-cli';
import * as fs from 'fs';

CompilerHost.prototype.getCanonicalFileName =
  function mockGetCanonicalFileName(fileName: string, index: number = 0): string {
    const segments = fileName.replace(/^\//, '').split('/');

    if (!segments[index]) {
      return fileName;
    }

    const ls = fs.readdirSync(index ? '/' + segments.slice(0, index).join('/') : '/');

    segments[index] = ls.find(item => {
      return item.toLowerCase() === segments[index].toLowerCase();
    }) as string;

    return mockGetCanonicalFileName('/' + segments.join('/'), index + 1);
  };

Put that at the beginning of your webpack config

What is does is to override getCanonicalFileName that now simply returns the same path given, with the corrected path (with the right case in filesystem)

So for example if the route in your disk is /Users/test/Documents/project/file.ts but typescript is returning /users/test/documents/project/file.ts (the cause of this issue), this function will go looking folder from folder in that path and building the url again with the correct case.

Tested in my project and it worked without a complain.

@tbosch, feel free to use this code, or a modification to patch this if you think it's the right solution.

More Issues: