angular-cli: Cannot read property 'replace' of undefined when running --aot build

Please provide us with the following information:

OS?

Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)

Windows Server 2012 and Mac OSX 10.12.1

Versions.

Please run ng --version. If there’s nothing outputted, please run in a Terminal: node --version and paste the result here:

angular-cli: 1.0.0-beta.20-4 node: 6.9.1 os: darwin x64

Repro steps.

Was this an app that wasn’t created using the CLI? What change did you do on your code? etc.

Created using CLI

"dependencies": {
    "@angular/common": "^2.1.0",
    "@angular/compiler": "^2.1.0",
    "@angular/core": "^2.1.0",
    "@angular/forms": "^2.1.0",
    "@angular/http": "^2.1.0",
    "@angular/material": "^2.0.0-alpha.10",
    "@angular/platform-browser": "^2.1.0",
    "@angular/platform-browser-dynamic": "^2.1.0",
    "@angular/router": "^3.1.0",
    "core-js": "^2.4.1",
    "jquery": "^3.1.1",
    "ms-signalr-client": "^2.2.5",
    "primeng": "^1.0.0-rc.6",
    "primeui": "^4.1.15",
    "rxjs": "5.0.0-beta.12",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.6.23"
  },
  "devDependencies": {
    "@angular/compiler-cli": "^2.1.0",
    "@types/jasmine": "^2.2.30",
    "@types/node": "^6.0.42",
    "angular-cli": "1.0.0-beta.20-4",
    "codelyzer": "~1.0.0-beta.3",
    "jasmine-core": "2.4.1",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "1.2.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.2.1",
    "protractor": "4.0.9",
    "ts-node": "1.2.1",
    "tslint": "3.13.0",
    "typescript": "~2.0.3",
    "webdriver-manager": "10.2.5"
  }

The log given by the failure.

Normally this include a stack trace and some more information.

ERROR in ./src/app/app.module.ngfactory.ts
Module build failed: TypeError: Cannot read property 'replace' of undefined
    at Object.normalizeSlashes (/Users/gordonchen/Documents/Work/Angular-2-Web/node_modules/typescript/lib/typescript.js:1771:20)
    at writeReferencePath (/Users/gordonchen/Documents/Work/Angular-2-Web/node_modules/typescript/lib/typescript.js:37236:90)
    at /Users/gordonchen/Documents/Work/Angular-2-Web/node_modules/typescript/lib/typescript.js:35750:29
    at Object.forEach (/Users/gordonchen/Documents/Work/Angular-2-Web/node_modules/typescript/lib/typescript.js:1115:30)
    at /Users/gordonchen/Documents/Work/Angular-2-Web/node_modules/typescript/lib/typescript.js:35742:20
    at Object.forEach (/Users/gordonchen/Documents/Work/Angular-2-Web/node_modules/typescript/lib/typescript.js:1115:30)
    at emitDeclarations (/Users/gordonchen/Documents/Work/Angular-2-Web/node_modules/typescript/lib/typescript.js:35735:12)
    at getDeclarationDiagnosticsFromFile (/Users/gordonchen/Documents/Work/Angular-2-Web/node_modules/typescript/lib/typescript.js:35699:13)
    at onSingleFileEmit (/Users/gordonchen/Documents/Work/Angular-2-Web/node_modules/typescript/lib/typescript.js:7569:13)
    at Object.forEachExpectedEmitFile (/Users/gordonchen/Documents/Work/Angular-2-Web/node_modules/typescript/lib/typescript.js:7542:21)
    at Object.getDeclarationDiagnostics (/Users/gordonchen/Documents/Work/Angular-2-Web/node_modules/typescript/lib/typescript.js:35695:12)
    at /Users/gordonchen/Documents/Work/Angular-2-Web/node_modules/typescript/lib/typescript.js:45673:27
    at runWithCancellationToken (/Users/gordonchen/Documents/Work/Angular-2-Web/node_modules/typescript/lib/typescript.js:45468:24)
    at getDeclarationDiagnosticsWorker (/Users/gordonchen/Documents/Work/Angular-2-Web/node_modules/typescript/lib/typescript.js:45669:20)
    at Object.getDeclarationDiagnostics (/Users/gordonchen/Documents/Work/Angular-2-Web/node_modules/typescript/lib/typescript.js:45457:24)
    at _transpile (/Users/gordonchen/Documents/Work/Angular-2-Web/node_modules/@ngtools/webpack/src/loader.js:92:29)
    at /Users/gordonchen/Documents/Work/Angular-2-Web/node_modules/@ngtools/webpack/src/loader.js:128:26
    at process._tickCallback (internal/process/next_tick.js:103:7)
 @ ./src/main.ts 4:0-64
 @ multi main

Mention any other details that might be useful.

Error occurs twice both on a module.ngfactory.ts when running with --aot only

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 10
  • Comments: 19 (1 by maintainers)

Most upvoted comments

I’ve faced the flattenStyles exception. For me, it was caused by a component with a style sheet referenced in styleUrl but also with ViewEncapsulation === None. It’s going to be hoisted anyway so I moved it to a partials folder and referenced it in angular-cli.json styles:[].

@rkusuma https://github.com/angular/angular-cli/issues/3399

We can use ViewEncapsulation with --aot, but not a combination of them AND styleUrls / styles. The current workaround is, if you need styles for that non-encapsulated component to include the styles in the angular-cli.json.

Just spent hours fixing this. It was caused by a single instance of

/// <reference path="..." />

the Object.normalizeSlashes was the clue!

I don’t think any of these issues are fixable in the CLI per se. They all seem to be AoT related errors that you’d get by compiling your code with ngc without the CLI. ngc compilation is overall more strict than tsc.

The best place for AoT/ngc related errors is https://github.com/angular/angular.

@nickmorton Thanks! thats exactly the issue going on.