Recently, our frontend build started failing on our build server. I managed to reproduce the problem on my local machine after running npm cache clean and removing the node_modules directory from the project directory of our frontend.
The error is as follows:
Jeroen@host:~/project/project-gui/frontend$ ng build
Hash: 68b2d23b79565fad2e33
Time: 15457ms
chunk {0} main.bundle.js, main.bundle.map (main) 184 kB {2} [initial] [rendered]
chunk {1} styles.bundle.css, styles.bundle.map, styles.bundle.map (styles) 153 kB {3} [initial] [rendered]
chunk {2} vendor.bundle.js, vendor.bundle.map (vendor) 3.44 MB [initial] [rendered]
chunk {3} inline.bundle.js, inline.bundle.map (inline) 0 bytes [entry] [rendered]
ERROR in ./~/angular2-logger/app/core/logger.ts
Module build failed: TypeError: Cannot read property 'text' of undefined
at IdentifierObject.TokenOrIdentifierObject.getText (/home/Jeroen/project/project-gui/frontend/node_modules/typescript/lib/typescript.js:53644:56)
at /home/Jeroen/project/project-gui/frontend/node_modules/@ngtools/webpack/src/loader.js:83:72
at Array.some (native)
at /home/Jeroen/project/project-gui/frontend/node_modules/@ngtools/webpack/src/loader.js:83:32
at Array.filter (native)
at _removeModuleId (/home/Jeroen/project/project-gui/frontend/node_modules/@ngtools/webpack/src/loader.js:82:10)
at /home/Jeroen/project/project-gui/frontend/node_modules/@ngtools/webpack/src/loader.js:167:48
@ ./~/angular2-logger/core.js 6:9-37
@ ./src/app/app.module.ts
@ ./src/app/index.ts
@ ./src/main.ts
@ multi main
ERROR in ./~/angular2-logger/app/core/providers.ts
Module build failed: TypeError: Cannot read property 'text' of undefined
at IdentifierObject.TokenOrIdentifierObject.getText (/home/Jeroen/project/project-gui/frontend/node_modules/typescript/lib/typescript.js:53644:56)
at /home/Jeroen/project/project-gui/frontend/node_modules/@ngtools/webpack/src/loader.js:83:72
at Array.some (native)
at /home/Jeroen/project/project-gui/frontend/node_modules/@ngtools/webpack/src/loader.js:83:32
at Array.filter (native)
at _removeModuleId (/home/Jeroen/project/project-gui/frontend/node_modules/@ngtools/webpack/src/loader.js:82:10)
at /home/Jeroen/project/project-gui/frontend/node_modules/@ngtools/webpack/src/loader.js:167:48
@ ./~/angular2-logger/core.js 7:9-40
@ ./src/app/app.module.ts
@ ./src/app/index.ts
@ ./src/main.ts
@ multi main
I've updated angular-cli to the latest version (1.0.0-beta.25.5).
My package.json looks like this:
{
"name": "project",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.conf.json",
"lint": "tslint \"src/**/*.ts\" --project src/tsconfig.json --type-check && tslint \"e2e/**/*.ts\" --project e2e/tsconfig.json --type-check",
"test": "ng test",
"pree2e": "webdriver-manager update --standalone false --gecko false",
"e2e": "protractor",
"build": "ng build -p --progress false"
},
"private": true,
"dependencies": {
"@angular/common": "^2.3.1",
"@angular/compiler": "^2.3.1",
"@angular/core": "^2.3.1",
"@angular/forms": "^2.3.1",
"@angular/http": "^2.3.1",
"@angular/platform-browser": "^2.3.1",
"@angular/platform-browser-dynamic": "^2.3.1",
"@angular/router": "^3.3.1",
"angular2-logger": "0.5.1",
"angular2-uuid": "1.1.0",
"bootstrap": "^3.3.6",
"core-js": "^2.4.1",
"rxjs": "^5.0.1",
"ts-helpers": "^1.1.1",
"zone.js": "^0.7.2"
},
"devDependencies": {
"@angular/compiler-cli": "^2.3.1",
"@types/jasmine": "2.5.38",
"@types/node": "^6.0.42",
"angular-cli": "1.0.0-beta.25.5",
"codelyzer": "~2.0.0-beta.1",
"jasmine-core": "2.5.2",
"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.13",
"ts-node": "1.2.1",
"tslint": "^4.3.0",
"typescript": "~2.0.3"
}
}
And here is what logger.ts looks like;
import {Injectable, Optional} from "@angular/core";
import {Level} from "./level";
/**
* Logger options.
* See {@link Logger}.
*
* level - How much detail you want to see in the logs, 0 being off, 1 being the less detailed, 5 being the most. Defaults to WARN.
* global - Whether you want the created logger object to be exposed in the global scope. Defaults to true.
* globalAs - The window's property name that will hold the logger object created. Defaults to 'logger'.
* store - Whether you want the level config to be saved in the local storage so it doesn't get lost when you refresh. Defaults to false.
* storeAs - The local storage key that will be used to save the level config if the store setting is true. Defaults to 'angular2.logger.level'.
*
* Created by Langley on 3/23/2016.
*
*/
export class Options {
level: Level;
global: boolean;
globalAs: string;
store: boolean;
storeAs: string;
}
// For browsers that don't implement the debug method, log will be used instead. Fixes #62.
const CONSOLE_DEBUG_METHOD = console["debug"] ? "debug" : "log";
// Temporal until https://github.com/angular/angular/issues/7344 gets fixed.
const DEFAULT_OPTIONS: Options = {
level: Level.WARN,
global: true,
globalAs: "logger",
store: false,
storeAs: "angular2.logger.level"
};
@Injectable()
export class Logger {
private _level: Level;
private _globalAs: string;
private _store: boolean;
private _storeAs: string;
public Level: any = Level;
constructor( @Optional() options?: Options ) {
// Move this to the constructor definition when optional parameters are working with @Injectable: https://github.com/angular/angular/issues/7344
let { level, global, globalAs, store, storeAs } = Object.assign( {}, DEFAULT_OPTIONS, options );
this._level = level;
this._globalAs = globalAs;
this._storeAs = storeAs;
global && this.global();
if ( store || this._loadLevel() ) this.store();
}
private _loadLevel = (): Level => Number(localStorage.getItem( this._storeAs ));
private _storeLevel(level: Level) { localStorage[ this._storeAs ] = level; }
error(message?: any, ...optionalParams: any[]) {
this.isErrorEnabled() && console.error.apply( console, arguments );
}
warn(message?: any, ...optionalParams: any[]) {
this.isWarnEnabled() && console.warn.apply( console, arguments );
}
info(message?: any, ...optionalParams: any[]) {
this.isInfoEnabled() && console.info.apply( console, arguments );
}
debug(message?: any, ...optionalParams: any[]) {
this.isDebugEnabled() && ( <any> console )[ CONSOLE_DEBUG_METHOD ].apply( console, arguments );
}
log(message?: any, ...optionalParams: any[]) {
this.isLogEnabled() && console.log.apply( console, arguments );
}
global = () => ( <any> window )[this._globalAs] = this;
store(): Logger {
this._store = true;
let storedLevel = this._loadLevel();
if ( storedLevel ) { this._level = storedLevel; }
else { this._storeLevel( this.level ); }
return this;
}
unstore(): Logger {
this._store = false;
localStorage.removeItem( this._storeAs );
return this;
}
isErrorEnabled = (): boolean => this.level >= Level.ERROR;
isWarnEnabled = (): boolean => this.level >= Level.WARN;
isInfoEnabled = (): boolean => this.level >= Level.INFO;
isDebugEnabled = (): boolean => this.level >= Level.DEBUG;
isLogEnabled = (): boolean => this.level >= Level.LOG;
get level(): Level { return this._level; }
set level(level: Level) {
this._store && this._storeLevel(level);
this._level = level;
}
}