1

I research some post before but I didn't find a solution for this problem that I'm having this week that I didn't have in the past with the kind of the same code.

My problem is coming on VSTS - Hosted Agent, I'm trying to build the project in there, and It's triggering this error, and after try all the ideas I got, just asking here.

Just to remark that working locally, on my machine, it works perfectly.

Some of the things I tried are:

  • Update cli to latest version
  • Update ts to latest version
  • Remove typings references from main.ts (it produces other issues)

So, this is the main.ts

/// <reference path="../typings/index.d.ts" />
require('core-js/shim');
require('zone.js/dist/zone');
require('reflect-metadata/temp/Reflect');

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
import { IEnvironment } from './_shared/entities/interfaces/index';
declare let environment: IEnvironment;

if (environment.production) {
    enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule);

this is the short error log:

./src/app/main.ts
Module build failed: TypeError: Cannot read property 'replace' of undefined
  at Object.normalizeSlashes

this is the long error log:

0% compiling 10% building modules 0/1 modules 1 active multi main            10% building modules 1/1 modules 0 active 10% building modules 1/2 modules 1 active multi styles              10% building modules 2/2 modules 0 active 10% building modules 2/3 modules 1 active multi scripts               10% building modules 3/3 modules 0 active 10% building modules 3/4 modules 1 active ...ode_modules\signalr\jquery.signalR.js                                          10% building modules 4/4 modules 0 active 10% building modules 4/5 modules 1 active ...node_modules\underscore\underscore.js                                          10% building modules 5/5 modules 0 active 10% building modules 5/6 modules 1 active ...\s\node_modules\jquery\dist\jquery.js                                          10% building modules 6/6 modules 0 active 10% building modules 6/7 modules 1 active ...odules\bootstrap\dist\js\bootstrap.js                                          10% building modules 7/7 modules 0 active 10% building modules 7/8 modules 1 active ...node_modules\tether\dist\js\tether.js                                          10% building modules 8/8 modules 0 active 10% building modules 8/9 modules 1 active ....js?sourcemap!C:\a\1\s\src\style.scss                                          11% building modules 9/9 modules 0 active 11% building modules 9/10 modules 1 active ...js?sourcemap!C:\a\1\s\src\vendor.scss                                         11% building modules 10/10 modules 0 active 11% building modules 10/11 modules 1 active ...s\font-awesome\scss\font-awesome.scss                                          11% building modules 11/11 modules 0 active 11% building modules 11/12 modules 1 active ...ode_modules\signalr\jquery.signalR.js 11% building modules 11/13 modules 2 active ...node_modules\underscore\underscore.js 11% building modules 11/14 modules 3 active ...\s\node_modules\jquery\dist\jquery.js 11% building modules 11/15 modules 4 active ...odules\bootstrap\dist\js\bootstrap.js 11% building modules 11/16 modules 5 active ...node_modules\tether\dist\js\tether.js 11% building modules 11/17 modules 6 active ....js?sourcemap!C:\a\1\s\src\style.scss 11% building modules 11/18 modules 7 active ...js?sourcemap!C:\a\1\s\src\vendor.scss 11% building modules 11/19 modules 8 active ...s\font-awesome\scss\font-awesome.scss 11% building modules 11/20 modules 9 active ...src\index.js!C:\a\1\s\src\app\main.ts 11% building modules 11/21 modules 10 active ...de_modules\script-loader\addScript.js 11% building modules 11/22 modules 11 active ...ode_modules\style-loader\addStyles.js 11% building modules 12/22 modules 10 active ...ode_modules\style-loader\addStyles.js  11% building modules 13/22 modules 9 active ...ode_modules\style-loader\addStyles.js 11% building modules 14/22 modules 8 active ...ode_modules\style-loader\addStyles.js 11% building modules 15/22 modules 7 active ...ode_modules\style-loader\addStyles.js 11% building modules 16/22 modules 6 active ...ode_modules\style-loader\addStyles.js 12% building modules 17/22 modules 5 active ...ode_modules\style-loader\addStyles.js 12% building modules 18/22 modules 4 active ...s\font-awesome\scss\font-awesome.scss 12% building modules 19/22 modules 3 active ...s\font-awesome\scss\font-awesome.scss 12% building modules 20/22 modules 2 active ...s\font-awesome\scss\font-awesome.scss 12% building modules 20/23 modules 3 active ...de_modules\css-loader\lib\css-base.js 12% building modules 21/23 modules 2 active ...s\font-awesome\scss\font-awesome.scss 12% building modules 22/23 modules 1 active ...js?sourcemap!C:\a\1\s\src\vendor.scss 12% building modules 22/24 modules 2 active ...fonts\fontawesome-webfont.eot?v=4.7.0 12% building modules 22/25 modules 3 active ...awesome\fonts\fontawesome-webfont.eot 12% building modules 22/26 modules 4 active ...fonts\fontawesome-webfont.svg?v=4.7.0 12% building modules 22/27 modules 5 active ...nts\fontawesome-webfont.woff2?v=4.7.0 12% building modules 22/28 modules 6 active ...onts\fontawesome-webfont.woff?v=4.7.0 12% building modules 22/29 modules 7 active ...fonts\fontawesome-webfont.ttf?v=4.7.0 12% building modules 23/29 modules 6 active ...fonts\fontawesome-webfont.ttf?v=4.7.0 12% building modules 24/29 modules 5 active ...fonts\fontawesome-webfont.ttf?v=4.7.0 13% building modules 25/29 modules 4 active ...fonts\fontawesome-webfont.ttf?v=4.7.0 13% building modules 26/29 modules 3 active ...fonts\fontawesome-webfont.ttf?v=4.7.0 13% building modules 27/29 modules 2 active ...fonts\fontawesome-webfont.ttf?v=4.7.0 13% building modules 28/29 modules 1 active ...js?sourcemap!C:\a\1\s\src\vendor.scss                                          13% building modules 29/29 modules 0 active 13% building modules 29/30 modules 1 active ...\node_modules\animate.css\animate.css                                          13% building modules 30/30 modules 0 active                                 71% sealing 72% optimizing 73% basic module optimization       74% module optimization 75% advanced module optimization     76% basic chunk optimization 76% basic chunk optimization pass 2 76% basic chunk optimization pass 3              77% chunk optimization 78% advanced chunk optimization 79% module and chunk tree optimization                    80% module reviving 81% module order optimization    82% module id optimization         83% chunk reviving 84% chunk order optimization    85% chunk id optimization               86% hashing 87% module assets processing  88% chunk assets processing 89% additional chunk assets processing                          90% recording 91% additional asset processing    92% chunk asset optimization       94% asset optimization           95% emitting             Hash: [1m0afac734d2396ef89b20[39m[22m
2016-12-08T17:37:42.0619446Z Time: [1m9032[39m[22mms
2016-12-08T17:37:42.0619446Z chunk    {[1m[33m0[39m[22m} [1m[32mstyles.bundle.js, styles.bundle.map[39m[22m (styles) 290 kB {[1m[33m3[39m[22m}[1m[33m [initial][39m[22m[1m[32m [rendered][39m[22m
2016-12-08T17:37:42.0619446Z chunk    {[1m[33m1[39m[22m} [1m[32mscripts.bundle.js, scripts.bundle.map[39m[22m (scripts) 649 kB {[1m[33m3[39m[22m}[1m[33m [initial][39m[22m[1m[32m [rendered][39m[22m
2016-12-08T17:37:42.0619446Z chunk    {[1m[33m2[39m[22m} [1m[32mmain.bundle.js, main.bundle.map[39m[22m (main) 2.54 kB[1m[33m [initial][39m[22m[1m[32m [rendered][39m[22m
2016-12-08T17:37:42.0619446Z chunk    {[1m[33m3[39m[22m} [1m[32minline.bundle.js, inline.bundle.map[39m[22m (inline) 0 bytes[1m[33m [entry][39m[22m[1m[32m [rendered][39m[22m
2016-12-08T17:37:42.0619446Z 
2016-12-08T17:37:42.0619446Z [1m[31mERROR in ./src/app/main.ts
2016-12-08T17:37:42.0619446Z Module build failed: TypeError: Cannot read property 'replace' of undefined
2016-12-08T17:37:42.0619446Z     at Object.normalizeSlashes (C:\a\1\s\node_modules\typescript\lib\typescript.js:1771:20)
2016-12-08T17:37:42.0619446Z     at writeReferencePath (C:\a\1\s\node_modules\typescript\lib\typescript.js:37236:90)
2016-12-08T17:37:42.0619446Z     at C:\a\1\s\node_modules\typescript\lib\typescript.js:35750:29
2016-12-08T17:37:42.0629440Z     at Object.forEach (C:\a\1\s\node_modules\typescript\lib\typescript.js:1115:30)
2016-12-08T17:37:42.0629440Z     at C:\a\1\s\node_modules\typescript\lib\typescript.js:35742:20
2016-12-08T17:37:42.0629440Z     at Object.forEach (C:\a\1\s\node_modules\typescript\lib\typescript.js:1115:30)
2016-12-08T17:37:42.0629440Z     at emitDeclarations (C:\a\1\s\node_modules\typescript\lib\typescript.js:35735:12)
2016-12-08T17:37:42.0629440Z     at getDeclarationDiagnosticsFromFile (C:\a\1\s\node_modules\typescript\lib\typescript.js:35699:13)
2016-12-08T17:37:42.0629440Z     at onSingleFileEmit (C:\a\1\s\node_modules\typescript\lib\typescript.js:7569:13)
2016-12-08T17:37:42.0629440Z     at Object.forEachExpectedEmitFile (C:\a\1\s\node_modules\typescript\lib\typescript.js:7542:21)
2016-12-08T17:37:42.0629440Z     at Object.getDeclarationDiagnostics (C:\a\1\s\node_modules\typescript\lib\typescript.js:35695:12)
2016-12-08T17:37:42.0629440Z     at C:\a\1\s\node_modules\typescript\lib\typescript.js:45673:27
2016-12-08T17:37:42.0629440Z     at runWithCancellationToken (C:\a\1\s\node_modules\typescript\lib\typescript.js:45468:24)
2016-12-08T17:37:42.0629440Z     at getDeclarationDiagnosticsWorker (C:\a\1\s\node_modules\typescript\lib\typescript.js:45669:20)
2016-12-08T17:37:42.0629440Z     at getDeclarationDiagnosticsForFile (C:\a\1\s\node_modules\typescript\lib\typescript.js:45677:60)
2016-12-08T17:37:42.0629440Z     at getDiagnosticsHelper (C:\a\1\s\node_modules\typescript\lib\typescript.js:45436:24)
2016-12-08T17:37:42.0629440Z     at Object.getDeclarationDiagnostics (C:\a\1\s\node_modules\typescript\lib\typescript.js:45460:24)
2016-12-08T17:37:42.0629440Z     at TypeScriptFileRefactor.getDiagnostics (C:\a\1\s\node_modules\@ngtools\webpack\src\refactor.js:51:35)
2016-12-08T17:37:42.0629440Z     at _checkDiagnostics (C:\a\1\s\node_modules\@ngtools\webpack\src\loader.js:106:32)
2016-12-08T17:37:42.0629440Z     at C:\a\1\s\node_modules\@ngtools\webpack\src\loader.js:140:17
2016-12-08T17:37:42.0629440Z     at tryCatch (C:\a\1\s\node_modules\es6-promise\dist\es6-promise.js:410:12)
2016-12-08T17:37:42.0629440Z     at invokeCallback (C:\a\1\s\node_modules\es6-promise\dist\es6-promise.js:425:13)
2016-12-08T17:37:42.0629440Z     at publish (C:\a\1\s\node_modules\es6-promise\dist\es6-promise.js:393:7)
2016-12-08T17:37:42.0629440Z     at flush (C:\a\1\s\node_modules\es6-promise\dist\es6-promise.js:121:5)
2016-12-08T17:37:42.0629440Z     at _combinedTickCallback (internal/process/next_tick.js:67:7)
2016-12-08T17:37:42.0629440Z     at process._tickCallback (internal/process/next_tick.js:98:9)
2016-12-08T17:37:42.0629440Z  @ multi main[39m[22m

EDIT. ADDING... Package.json

{
  "name": "app",
  "version": "1.0.0",
  "description": "",
  "main": "src/app/main.ts",
  "scripts": {
    "build": "ng build",
    "start": "ng serve --host 0.0.0.0 --port 8080 --live-reload-port 49153",
    "dev": "ng build && npm start",
    "lint": "tslint --project ./tslint.json",
    "test": "ng test --watch=false",
    "postinstall": "gulp delete:types",
    "compile-ts": "node node_modules/typescript/lib/tsc.js -p ./tsconfig.json",
    "compile-sass": "gulp sass-compiler",
    "compile": "npm run compile-ts && npm run compile-sass",
    "clean": "gulp delete",
    "zip": "gulp zip"
  },
  "author": "me",
  "license": "MIT",
  "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/platform-browser": "~2.1.0",
    "@angular/platform-browser-dynamic": "~2.1.0",
    "@angular/router": "~3.1.0",
    "@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.14",
    "angular-cli": "^1.0.0-beta.18",
    "animate.css": "^3.5.2",
    "bootstrap": "^4.0.0-alpha.4",
    "core-js": "^2.4.1",
    "font-awesome": "^4.6.3",
    "jquery": "^3.1.1",
    "karma-phantomjs-launcher": "^1.0.2",
    "ng2-pagination": "^0.5.1",
    "reflect-metadata": "^0.1.8",
    "rxjs": "5.0.0-beta.12",
    "signalr": "^2.2.1",
    "systemjs": "0.19.39",
    "underscore": "^1.8.3",
    "zone.js": "^0.6.23"
  },
  "devDependencies": {
    "codelyzer": "^1.0.0-beta.4",
    "del": "^2.2.1",
    "gulp": "^3.9.1",
    "gulp-fail": "^1.0.5",
    "gulp-sass": "^2.3.2",
    "gulp-zip": "^3.0.2",
    "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",
    "ts-node": "1.2.1",
    "tslint": "3.15.1",
    "typescript": "~2.0.3",
    "typings": "^1.4.0"
  }
}
Alejandro Lora
  • 7,203
  • 3
  • 18
  • 34
  • Can you check if you are using type references somewhere? `/// ` Update: my bad I see it right in the main.ts file. Can you try using npm @types instead? – borislemke Dec 09 '16 at 10:24
  • It is likely to be a problem with your `/// ` in main.ts. I think the guys at cli dropped support for this sometime ago – borislemke Dec 09 '16 at 10:26
  • Hi @borislemke, it was working for me before the typings, I dont want to switch to '@types' by now and if I'm not using the latest version of angular-cli it should works, right? – Alejandro Lora Dec 09 '16 at 10:32
  • maybe I should try, but not sure why locally is working fine and not in the server – Alejandro Lora Dec 09 '16 at 10:36
  • 1
    I'm guessing there are differences in software version on your local and remote machines, but this is only an assumption. In the mean time, you can just build your app locally and upload the compiled assets - there should be no issues running the app on the server. But yes, please try to switch to node @types instead of d.ts files for now – borislemke Dec 09 '16 at 10:55
  • Thanks @borislemke for your time, I was creating a ticket on angular-cli repo and I did realize that I was having a caret "^" for the angular-cli package, so I wasn't using the one that I though... I'll leave more details in the answer, thanks for your time :-) and you're right, it's because versioning – Alejandro Lora Dec 09 '16 at 11:13

2 Answers2

0

I just created a ticket on the angular-cli repository asking for this problem, and did realize that I was using caret "^" for the angular-cli version on package.json, that means that I wasn't using the version that I did believe.

I removed, and forcing to use that one, 1.0.0-beta.18, it works now.

Still, I do not understand why it does not work with a newer version on VSTS and it does on local, but for me, this work around is valid.

This is the ticket I created, just in case you wanna have a look and it might help someone else.

https://github.com/angular/angular-cli/issues/3491

Alejandro Lora
  • 7,203
  • 3
  • 18
  • 34
0

I stumbled on this post because the error I was getting was this:

Module build failed: TypeError: Cannot read property 'replace' of undefined

(my error and my project isn't even vaguely related to OP's question though)

My mistake was that I had installed node and npm in my WSL too and this was creating conflicts with the installation in windows. I followed these instructions to remove node and npm from ubuntu (they are still installed on windows) and now everything works.