2017-04-26 59 views
0

我正在使用angular-cli和webpack2的Angular 4應用程序。Angular 4,ng構建期間意外的令牌錯誤 - 產品

我可以成功地建立與ng build

但是這個項目,當我運行ng build --prod以下錯誤被拋出:在main.50d83f3f70f7e607ec7a.bundle.js從UglifyJs意外 令牌

ERROR:名稱(FilterPipe)[main.50d83f3f70f7e607ec7a.bundle.js:7,6]

我不明白什麼是錯的。

這裏是我的filter.pipe.ts文件:

import {Pipe, PipeTransform } from '@angular/core'; 

@Pipe({ 
    name: 'filter' 
}) 

export class FilterPipe implements PipeTransform { 
    transform(items: any[], field : string, value : string): any[] { 
     if (!items) return []; 
     return items.filter(it => it[field] == value); 
    } 
} 
+3

檢查你的目標不是ES6,這已經知道問題醜化。 – 2017-04-26 14:44:07

回答

2

這是因爲醜化犯規支持ES6語法呢。

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

修改tsconfig.json檢查FR確保 「目標」: 「ES5」,是有實例:

{ 
    "compileOnSave": false, 
    "compilerOptions": { 
    "outDir": "./dist/out-tsc", 
    "baseUrl": "src", 
    "sourceMap": true, 
    "declaration": false, 
    "moduleResolution": "node", 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "target": "es5", 
    "typeRoots": [ 
     "node_modules/@types" 
    ], 
    "lib": [ 
     "es2016", 
     "dom" 
    ] 
    } 
} 
+0

我已經改變了我的tsconfig.json有一個「目標」:「es5」,我仍然得到這個錯誤。我需要採取哪些額外步驟來確保其正常工作? –

+0

@JustinGrahn我正面臨類似的問題。你有沒有設法找到解決方案? – kds23

+0

@ kds23哦,男孩,我做了,但一次發生了多個問題,所以讓我試着回頭。我認爲我所遇到的第一個問題是通過強制使用不同版本的Uglify來解決的。搜索周圍,但有一個Angular或Typescript線程詳細說明了爲什麼這是必要的。其次,JIT編譯器允許我的組件html引用專用變量,無論出於何種原因,在使用-prod標誌使用的AOT編譯器編譯時實際上都不允許這些變量,所以我不得不將每個由我引用的私有變量HTML。我認爲Uglify版本是你最好的選擇 –