由于Uglify.js,Angular构建失败

时间:2017-06-02 23:24:41

标签: angular typescript angular-cli

今天早上我们遇到了一个问题,我们的构建失败了,原因完全不为人知。堆栈跟踪不会显示Uglify文件之外的任何内容,突然间我们遇到了这个问题。我正在使用Angular CLI

ng build --target=production --env=prod

 18% building modules 67/67 modules 0 activeTemplate parse warnings:                  
The <template> element is deprecated. Use <ng-template> instead ("[WARNING ->]<template #innerView></template>
<template #template let-ctx>
    <template [swapCmp]="ctx.component""): ng:///Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/angular2-modal/esm/overlay/overlay.component.d.ts.ModalOverlay.html@0:0
Warning: Can't resolve all parameters for UserDetail in /Users/shivganesh/Documents/Vetahealth/CODE/Physician/src/app/models/user-detail.model.ts: (?). This will become an error in Angular v5.x
Hash: 57f5ee6a7de2d0427083                                                                 
Time: 83888ms
chunk    {0} main.72d8abfc264b3e8c979e.bundle.js (main) 3.04 MB {3} [initial] [rendered]
chunk    {1} scripts.155fe32b210641a6bc1c.bundle.js (scripts) 1.15 MB {4} [initial] [rendered]
chunk    {2} styles.68eaa60430e83a5adf34.bundle.css (styles) 599 bytes {4} [initial] [rendered]
chunk    {3} vendor.7b3b095ed3817b60967b.bundle.js (vendor) 4.05 MB [initial] [rendered]
chunk    {4} inline.27f2c1c1353b86214c6d.bundle.js (inline) 0 bytes [entry] [rendered]

ERROR in main.72d8abfc264b3e8c979e.bundle.js from UglifyJs
TypeError: Cannot set property 'fixed' of undefined
    at TreeWalker.eval [as visit] (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:5581:25)
    at TreeWalker._visit (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:1339:24)
    at AST_This._walk (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:480:24)
    at AST_Dot.eval (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:1061:29)
    at TreeWalker._visit (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:1343:21)
    at AST_Dot._walk (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:1060:24)
    at AST_Dot.walk (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:483:21)
    at TreeWalker.eval [as visit] (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:5719:31)
    at TreeWalker._visit (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:1339:24)
    at AST_ForIn._walk (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:653:24)
    at walk_body (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:530:17)
    at AST_BlockStatement.eval (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:541:13)
    at TreeWalker._visit (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:1343:21)
    at AST_BlockStatement._walk (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:540:24)
    at AST_BlockStatement.walk (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:483:21)
    at TreeWalker.eval [as visit] (eval at <anonymous> (/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/webpack/node_modules/uglify-js/tools/node.js:1:1), <anonymous>:5698:42)

npm ERR! Darwin 16.6.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build"
npm ERR! node v7.9.0
npm ERR! npm  v4.2.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! vetahealth-admin@0.0.0 build: `ng build --target=production --env=prod`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the vetahealth-admin@0.0.0 build script 'ng build --target=production --env=prod'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the vetahealth-admin package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     ng build --target=production --env=prod
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs vetahealth-admin
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls vetahealth-admin
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/shivganesh/.npm/_logs/2017-06-02T22_40_30_878Z-debug.log

我很困惑为什么Uglify会这样做。直到上个星期一它一切都很好,今天突然间它破了。我也粘贴在我的package.json和npm日志下面。

的package.json

{
  "name": "vetahealth-admin",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "ng": "ng",
    "start": "ng serve --port 8080",
    "build": "ng build --target=production --env=prod",
    "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",
    "docs": "npm run typedoc -- --options typedoc.json --exclude '**/*.spec.ts' ./src/",
    "typedoc": "typedoc"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "4.1.3",
    "@angular/compiler": "4.1.3",
    "@angular/core": "4.1.3",
    "@angular/forms": "4.1.3",
    "@angular/http": "4.1.3",
    "@angular/platform-browser": "4.1.3",
    "@angular/platform-browser-dynamic": "4.1.3",
    "@angular/platform-server": "4.1.3",
    "@angular/router": "4.1.3",
    "@ngtools/webpack": "^1.3.1",
    "@swimlane/ngx-datatable": "9.3.0",
    "@angular/animations": "^4.0.0",
    "angular-2-local-storage": "^1.0.1",
    "angular2-highcharts": "^0.5.5",
    "angular2-modal": "^2.0.3",
    "angular2-moment": "^1.2.0",
    "angular2-text-mask": "^8.0.1",
    "angular2-toaster": "^4.0.0",
    "animate.css": "^3.5.2",
    "bootstrap": "^3.3.7",
    "core-js": "^2.4.1",
    "font-awesome": "^4.7.0",
    "install": "^0.10.1",
    "jquery": "^3.1.1",
    "metismenu": "^2.5.0",
    "moment": "^2.18.1",
    "npm": "^5.0.1",
    "pikaday": "^1.5.1",
    "primeng": "^4.0.1",
    "rxjs": "^5.0.1",
    "slimscroll": "^0.9.1",
    "ts-helpers": "^1.1.1",
    "typescript": "2.2.2",
    "underscore": "^1.8.3",
    "compass-mixins": "0.12.10",
    "zone.js": "^0.8.11"
  },
  "devDependencies": {
    "@angular/cli": "^1.0.0",
    "@angular/compiler-cli": "4.1.3",
    "@types/jasmine": "2.5.51",
    "@types/lodash": "4.14.65",
    "@types/moment": "^2.13.0",
    "@types/node": "^7.0.27",
    "codelyzer": "~3.0.1",
    "jasmine-core": "2.6.2",
    "jasmine-spec-reporter": "4.1.0",
    "karma": "1.7.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.6.0",
    "protractor": "~5.1.2",
    "ts-node": "3.0.4",
    "tslint": "^5.4.2",
    "typedoc": "^0.7.1",
    "typescript": "~2.3"
  }
}

Npm Logs

Shivs-MacBook-Pro:Physician shivganesh$ cat /Users/shivganesh/.npm/_logs/2017-06-02T22_40_30_878Z-debug.log
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'build' ]
2 info using npm@4.2.0
3 info using node@v7.9.0
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle vetahealth-admin@0.0.0~prebuild: vetahealth-admin@0.0.0
6 silly lifecycle vetahealth-admin@0.0.0~prebuild: no script for prebuild, continuing
7 info lifecycle vetahealth-admin@0.0.0~build: vetahealth-admin@0.0.0
8 verbose lifecycle vetahealth-admin@0.0.0~build: unsafe-perm in lifecycle true
9 verbose lifecycle vetahealth-admin@0.0.0~build: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/shivganesh/Documents/Vetahealth/CODE/Physician/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
10 verbose lifecycle vetahealth-admin@0.0.0~build: CWD: /Users/shivganesh/Documents/Vetahealth/CODE/Physician
11 silly lifecycle vetahealth-admin@0.0.0~build: Args: [ '-c', 'ng build --target=production --env=prod' ]
12 silly lifecycle vetahealth-admin@0.0.0~build: Returned: code: 1  signal: null
13 info lifecycle vetahealth-admin@0.0.0~build: Failed to exec build script
14 verbose stack Error: vetahealth-admin@0.0.0 build: `ng build --target=production --env=prod`
14 verbose stack Exit status 1
14 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:279:16)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at EventEmitter.emit (events.js:194:7)
14 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at ChildProcess.emit (events.js:194:7)
14 verbose stack     at maybeClose (internal/child_process.js:899:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
15 verbose pkgid vetahealth-admin@0.0.0
16 verbose cwd /Users/shivganesh/Documents/Vetahealth/CODE/Physician
17 error Darwin 16.6.0
18 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build"
19 error node v7.9.0
20 error npm  v4.2.0
21 error code ELIFECYCLE
22 error errno 1
23 error vetahealth-admin@0.0.0 build: `ng build --target=production --env=prod`
23 error Exit status 1
24 error Failed at the vetahealth-admin@0.0.0 build script 'ng build --target=production --env=prod'.
24 error Make sure you have the latest version of node.js and npm installed.
24 error If you do, this is most likely a problem with the vetahealth-admin package,
24 error not with npm itself.
24 error Tell the author that this fails on your system:
24 error     ng build --target=production --env=prod
24 error You can get information on how to open an issue for this project with:
24 error     npm bugs vetahealth-admin
24 error Or if that isn't available, you can get their info via:
24 error     npm owner ls vetahealth-admin
24 error There is likely additional logging output above.
25 verbose exit [ 1, true ]

1 个答案:

答案 0 :(得分:0)

所以解决这些问题的方法如下: -

  1. 检查以前的版本是否也有同样的问题,在我的情况下证明是真的。这样我消除了开发人员或解决方案在某处出错的疑问。
  2. 现在继续使用最新版本的angular-cli
  3. 创建一个新项目
  4. 上面的步骤为您提供了获取具有工作依赖关系的空白项目的选项。
  5. 列出各种依赖项,然后尝试将它们合并到正确的位置。
  6. 您可能会发现存在不匹配或不一致但请尝试至少获取针对角度文件提及的版本。
  7. 多数民众赞成。你完成了。我必须卸载ng版本,因为我系统上的angular-cli版本高于项目使用的版本。

    希望这有用。