2017-01-16 39 views
4

最近,我們的前端構建在構建服務器上開始失敗。在運行npm cache clean並從我們前端的項目目錄中刪除node_modules目錄後,我設法在本地機器上重現了問題。使用angular-cli構建angular2前端的錯誤

的錯誤如下:

[email protected]:~/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 

我已經更新角CLI到最新版本(1.0.0-beta.25.5)。

我的package.json看起來是這樣的:

{ 
    "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" 
    } 
} 

這裏是什麼logger.ts樣子;

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; 
    } 

}  
+0

你可以添加此文件:'angular2-logger/app/core/logger.ts'?它看起來像你的問題。 – Dinistro

回答

4

UPDATE 20-JAN-2017

angular-cli: 1.0.0-beta.26已經正式發佈,似乎解決這個問題。

OLD(過時)答

我相信你遇到類似this issueangular-cli項目正在跟蹤的東西。

angular-cli項目修復之前,回滾到angular-cli: 1.0.0-beta.21似乎可以解決問題。您可以按照project upgrade instructions降級至angular-cli: 1.0.0-beta.21。按照這些說明進行操作時,請務必用[email protected]替換npm install命令中的[email protected]

我覺得這也是值得一提的是,最新的角2個版本(2.4.3/router 3.4.3)似乎是工作的罰款與[email protected],所以你應該能夠保持這些版本在package.json文件,而不是使用ng init嘗試版本的讓你使用。