代码之家  ›  专栏  ›  技术社区  ›  Stefan Falk

为生产构建时出现“意外标记:punc())”

  •  2
  • Stefan Falk  · 技术社区  · 6 年前

    ng build --prod --aot 我收到以下非常简短的错误消息:

    $ ng build --prod
                                                                                             
    Date: 2019-01-26T17:26:45.018Z
    Hash: 979690c7a363996f24b8
    Time: 28274ms
    chunk {0} runtime.ea8176a0aa687d0c7546.js (runtime) 2.23 kB [entry] [rendered]
    chunk {1} common.78f3e0cd7d0f774768aa.js (common) 583 bytes  [rendered]
    chunk {2} main.5f97cda0f273b510e26a.js (main) 973 kB [initial] [rendered]
    chunk {3} polyfills.c2a7344c1c84ba3d2a73.js (polyfills) 58.2 kB [initial] [rendered]
    chunk {4} styles.1094b1dd78a0fa2c8fa7.css (styles) 85 kB [initial] [rendered]
    chunk {5} 5.92565e561816566c4426.js () 3.74 MB  [rendered]
    chunk {6} 6.a4ec6e690b75a22ddb72.js () 6.3 kB  [rendered]
    
    ERROR in 5.92565e561816566c4426.js from Terser
    Unexpected token: punc ()) [5.92565e561816566c4426.js:25865,4]
    

    我已经试过了 rm -rf node_modules/ .


    package.json

    {
      "name": "mz-admin",
      "version": "0.0.0",
      "license": "MIT",
      "scripts": {
        "ng": "ng",
        "start": "node server.js",
        "build": "ng build --prod",
        "test": "ng test",
        "lint": "ng lint",
        "e2e": "ng e2e"
      },
      "engines": {
        "node": "8.12.0",
        "npm": "6.4.1"
      },
      "private": true,
      "dependencies": {
        "@agm/core": "^1.0.0-beta.3",
        "@angular/animations": "7.1.0",
        "@angular/cdk": "^7.1.0",
        "@angular/cli": "7.0.6",
        "@angular/common": "7.1.0",
        "@angular/compiler": "7.1.0",
        "@angular/compiler-cli": "7.1.0",
        "@angular/core": "7.1.0",
        "@angular/flex-layout": "^7.0.0-beta.19",
        "@angular/forms": "7.1.0",
        "@angular/http": "7.1.0",
        "@angular/material": "^7.1.0",
        "@angular/material-moment-adapter": "^7.1.0",
        "@angular/platform-browser": "7.1.0",
        "@angular/platform-browser-dynamic": "7.1.0",
        "@angular/router": "7.1.0",
        "@fortawesome/angular-fontawesome": "^0.3.0",
        "@fortawesome/fontawesome-svg-core": "^1.2.4",
        "@fortawesome/free-brands-svg-icons": "^5.3.1",
        "@fortawesome/free-solid-svg-icons": "^5.3.1",
        "@ngx-share/button": "^7.0.0",
        "@ngx-share/core": "^7.0.0",
        "@types/braintree-web": "^3.6.4",
        "angular-mentions": "^0.8.0",
        "braintree-web": "^3.41.0",
        "braintree-web-drop-in": "^1.14.1",
        "chart.js": "^2.7.2",
        "core-js": "^2.5.7",
        "express": "^4.16.3",
        "http-status-codes": "^1.3.0",
        "ng-pick-datetime": "^7.0.0",
        "ngx-logger": "^3.1.0",
        "ngx-moment": "^3.1.0",
        "ngx-quill": "^4.5.0",
        "paypal-checkout": "^4.0.239",
        "quill": "^1.3.6",
        "quill-mention": "git+https://github.com/silentsnooc/quill-mention.git",
        "rxjs": "^6.3.2",
        "typescript": "^3.1.6",
        "zone.js": "^0.8.26"
      },
      "devDependencies": {
        "@angular-devkit/build-angular": "^0.10.6",
        "@angular/language-service": "7.1.0",
        "@types/googlemaps": "^3.30.16",
        "@types/jasmine": "^3.3.0",
        "@types/jasminewd2": "^2.0.6",
        "@types/node": "~10.12.10",
        "codelyzer": "^4.5.0",
        "enhanced-resolve": "^4.1.0",
        "express-http-proxy": "^1.5.0",
        "jasmine-core": "~3.3.0",
        "jasmine-spec-reporter": "~4.2.1",
        "karma": "~3.1.1",
        "karma-chrome-launcher": "~2.2.0",
        "karma-coverage-istanbul-reporter": "^2.0.4",
        "karma-jasmine": "~2.0.1",
        "karma-jasmine-html-reporter": "^1.4.0",
        "protractor": "^5.4.1",
        "ts-node": "~7.0.1",
        "tslint": "^5.11.0",
        "webpack-bundle-analyzer": "^3.0.3"
      }
    }
    

    生成日志的一部分

    [1m[33mWARNING in Terser Plugin: Dropping unused variable template [6.a4ec6e690b75a22ddb72.js:136,12][39m[22m
    
    [1m[33mWARNING in Terser Plugin: Dropping unused variable routes [6.a4ec6e690b75a22ddb72.js:148,4][39m[22m
    
    [1m[31mERROR in 5.92565e561816566c4426.js from Terser
    Unexpected token: punc ()) [5.92565e561816566c4426.js:25865,4][39m[22m
    Child [1mmini-css-extract-plugin node_modules/@angular-devkit/build-angular/src/angular-cli-files/plugins/raw-css-loader.js!node_modules/postcss-loader/src/index.js??extracted!node_modules/sass-loader/lib/loader.js??ref--14-3!src/styles.scss[39m[22m:
                       [1mAsset[39m[22m     [1mSize[39m[22m  [1mChunks[39m[22m  [1m[39m[22m[1m[39m[22m[1mChunk Names[39m[22m
        [1m[32m3rdpartylicenses.txt[39m[22m  1 bytes        [1m[39m[22m  [1m[32m[39m[22m
        Entrypoint [1mmini-css-extract-plugin[39m[22m = [1m[32m*[39m[22m
        chunk    {[1m[33m0[39m[22m} [1m[32m*[39m[22m (mini-css-extract-plugin) 102 KiB[1m[33m [entry][39m[22m[1m[32m [rendered][39m[22m
    Child [1mmini-css-extract-plugin node_modules/@angular-devkit/build-angular/src/angular-cli-files/plugins/raw-css-loader.js!node_modules/postcss-loader/src/index.js??extracted!node_modules/sass-loader/lib/loader.js??ref--14-3!src/theme.scss[39m[22m:
                       [1mAsset[39m[22m     [1mSize[39m[22m  [1mChunks[39m[22m  [1m[39m[22m[1m[39m[22m[1mChunk Names[39m[22m
        [1m[32m3rdpartylicenses.txt[39m[22m  1 bytes        [1m[39m[22m  [1m[32m[39m[22m
        Entrypoint [1mmini-css-extract-plugin[39m[22m = [1m[32m*[39m[22m
        chunk    {[1m[33m0[39m[22m} [1m[32m*[39m[22m (mini-css-extract-plugin) 55.6 KiB[1m[33m [entry][39m[22m[1m[32m [rendered][39m[22m
    
    WARNING in Terser Plugin: global_defs ngDevMode redefined [main.5f97cda0f273b510e26a.js:14309,21]
    
    WARNING in Terser Plugin: global_defs ngDevMode redefined [main.5f97cda0f273b510e26a.js:14510,25]
    
    WARNING in Terser Plugin: global_defs ngDevMode redefined [main.5f97cda0f273b510e26a.js:15652,21]
    
    WARNING in Terser Plugin: global_defs ngDevMode redefined [main.5f97cda0f273b510e26a.js:15658,21]
    

    --source-map

    $ ng build --prod --aot --source-map 
                                                                                                                   
    Date: 2019-01-26T22:31:44.106Z
    Hash: 51afc4cc158a10e520c6
    Time: 45390ms
    chunk {0} runtime.b29d49d6f279fff34f57.js, runtime.b29d49d6f279fff34f57.js.map (runtime) 2.29 kB [entry] [rendered]
    chunk {1} common.70409de1782336a79716.js, common.70409de1782336a79716.js.map (common) 639 bytes  [rendered]
    chunk {2} main.01e8ea6a2dd33c4e19d8.js, main.01e8ea6a2dd33c4e19d8.js.map (main) 970 kB [initial] [rendered]
    chunk {3} polyfills.22294cd4941de9604b91.js, polyfills.22294cd4941de9604b91.js.map (polyfills) 61.7 kB [initial] [rendered]
    chunk {4} styles.97ca4c55e9ba593fdf4c.css, styles.97ca4c55e9ba593fdf4c.css.map (styles) 85.5 kB [initial] [rendered]
    chunk {5} 5.33da963a3dd6decc5efc.js, 5.33da963a3dd6decc5efc.js.map () 1.9 MB  [rendered]
    chunk {6} 6.85bd192b02e86745d878.js, 6.85bd192b02e86745d878.js.map () 6.35 kB  [rendered]
    

    没有 --源地图

    $ ng build --prod --aot 
                                                                                             
    Date: 2019-01-26T22:32:18.173Z
    Hash: b5bcaa2123bb6718baf2
    Time: 28403ms
    chunk {0} runtime.0935b498984fda7c2e4f.js (runtime) 2.23 kB [entry] [rendered]
    chunk {1} common.78f3e0cd7d0f774768aa.js (common) 583 bytes  [rendered]
    chunk {2} main.2ae834dcaf8208d7aecd.js (main) 970 kB [initial] [rendered]
    chunk {3} polyfills.588b345e325a2549098e.js (polyfills) 61.7 kB [initial] [rendered]
    chunk {4} styles.088d5b7a7a0995d1df55.css (styles) 85.4 kB [initial] [rendered]
    chunk {5} 5.7e99fa00323b77c4e1c2.js () 3.82 MB  [rendered]
    chunk {6} 6.954a4978d0c6c411bb2f.js () 6.3 kB  [rendered]
    
    ERROR in 5.7e99fa00323b77c4e1c2.js from Terser
    Unexpected token: punc ()) [5.7e99fa00323b77c4e1c2.js:27338,4]
    

    具有 --source-map --named-chunks

    $ ng build --prod --source-map --named-chunks
                                                                                                                            
    Date: 2019-01-26T23:00:18.699Z
    Hash: c37b8f2ccfedbbf077fa
    Time: 61888ms
    chunk {0} runtime.a670ad696846ba781d64.js, runtime.a670ad696846ba781d64.js.map (runtime) 2.37 kB [entry] [rendered]
    chunk {1} common.d7fbf062c6d87ac4ade2.js, common.d7fbf062c6d87ac4ade2.js.map (common) 639 bytes  [rendered]
    chunk {2} component-application-application-module-ngfactory.22de247f215039a3cf63.js, component-application-application-module-ngfactory.22de247f215039a3cf63.js.map (component-application-application-module-ngfactory) 1.9 MB  [rendered]
    chunk {3} main.2897da054822ebda9646.js, main.2897da054822ebda9646.js.map (main) 973 kB [initial] [rendered]
    chunk {4} module-embedding-calendar-calendar-module-ngfactory.5b0025d2f887a5d7b22d.js, module-embedding-calendar-calendar-module-ngfactory.5b0025d2f887a5d7b22d.js.map (module-embedding-calendar-calendar-module-ngfactory) 6.4 kB  [rendered]
    chunk {5} polyfills.04ae14cfab6dbb09ad49.js, polyfills.04ae14cfab6dbb09ad49.js.map (polyfills) 61.7 kB [initial] [rendered]
    chunk {6} styles.52c1571339895f2464fa.css, styles.52c1571339895f2464fa.css.map (styles) 85.5 kB [initial] [rendered]
    

    看来

    ng build --prod --named-chunks --verbose --build-optimizer=false --source-map
    

    ERROR in component-application-application-module-ngfactory.7eb30a010bb7783ce652.js from Terser
    Unexpected token: punc ()) [./node_modules/quill-mention/src/quill.mention.js:183,0][component-application-application-module-ngfactory.7eb30a010bb7783ce652.js:29528,4]
    
    1 回复  |  直到 4 年前
        1
  •  36
  •   Stefan Falk    6 年前

    这一切都是从以下警告开始的:

    enter image description here

    --source-map 但也设置 --build-optimizer=false

    ng build --prod --named-chunks --verbose --build-optimizer=false --source-map
    
        2
  •  11
  •   Ashish Jain    5 年前

    在生产构建期间升级到angular 8之后,我得到了“来自Terser意外标记的common-es2015.xxx.js中的错误:Punc(;)[common-es2015.xxx.js]”

    在angular.json file-configurations-production部分中将sourceMap设置为true后,编译器显示了实际的文件名和错误行号。这是因为类文件中的变量声明中有一个额外的分号。

    putGamma: any = 0.0;; 
    
        3
  •  3
  •   dvque    5 年前

    残存物 中自定义.js文件中函数列表末尾的逗号 \src

    --source-map=true 还有设置 --build-optimizer=false angular.json 帮了我很多忙。

        4
  •  1
  •   masterxilo    5 年前

    我也有同样的问题,发现是因为 https://www.npmjs.com/package/url-parameter-append

    函数调用中的参数列表后有一个额外的逗号

    我在自己的url-parameter-append.js副本中删除了逗号,然后它就工作了。

    https://github.com/techinity/url-parameter-append/issues/10 ,但事实上,这个错误是

    • 在“Terser”中:在js/ts中,参数列表后面加一个逗号是合法的。
        5
  •  1
  •   Liran H    4 年前

    在我的例子中,它是由在一个特定的环境中使用ES6引起的 .js .js 文件的ES5代码修复了该问题。我曾经 ng build --prod --aot 检查错误是否消失。