“Unexpected token: punc ())” when building for production

后端 未结 4 1633
再見小時候
再見小時候 2020-12-29 06:14

If I try to test-build my application with ng build --prod --aot I get the following, quite short, error message:

$ ng build --prod
                      


        
相关标签:
4条回答
  • 2020-12-29 07:17

    It all started with this warning:

    It was this missing comma, which I put there to silence the warning, which rendered my project uncompileable.

    I was only able to locate this issue by using --source-map but also setting --build-optimizer=false

    ng build --prod --named-chunks --verbose --build-optimizer=false --source-map
    
    0 讨论(0)
  • 2020-12-29 07:18

    I had the same problem and found out it was caused by https://www.npmjs.com/package/url-parameter-append

    There was an extra comma after a list of parameters in a function call

    I removed the comma in my own copy of url-parameter-append.js and then it worked.

    I reported the bug to the author of that package https://github.com/techinity/url-parameter-append/issues/10 , but really IMO the bug is

    • in the way angular build reports errors
    • in "Terser": an extra comma after a list of parameters is legit in js/ts.
    0 讨论(0)
  • 2020-12-29 07:20

    In my case it was a leftover comma at the end of a list of functions inside a custom .js file in \src directory.

    The tip of by --source-map=true and also setting --build-optimizer=false in angular.json helped me a lot.

    0 讨论(0)
  • 2020-12-29 07:21

    After upgrading to angular 8 during production build, I was getting "Error in common-es2015.xxx.js from Terser Unexpected token: Punc(;) [common-es2015.xxx.js] "

    After setting sourceMap to true in angular.json file - configurations- production section, compiler displayed actual file name with error line number. It was due to an extra semicolon in a variable declaration in the class file.

    putGamma: any = 0.0;; 
    
    0 讨论(0)
提交回复
热议问题