-
Notifications
You must be signed in to change notification settings - Fork 12k
Third party ES2015 library causes build to hang/fail/be broken #12975
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Terser is encountering ES that is either invalid or it doesn't know how to parse. Run this command which presumably disables minification but still runs webpack in
which ought to yield the same input that would have been sent to Terser in the previous failing command. (Note: if webpack is run in You can then manually run each generated js file through the
Then put that failing generated file into a gist and post the link here. |
Thanks @kzc Terser completes successfully. Is there a way to see what options angular-cli is running it with? |
I've actually managed to work around the terser issue by using a custom builder, extending the webpack config and replacing the optimization using https://github.com/meltedspark/angular-builders It would be good to see what options angular is running it with so I can tweak it. |
That's unfortunate. It indicates that angular or webpack did not produce the same JS which caused the Terser parse error in production mode. |
I think it is the options that angular is sending to Terser. |
It's a parse error. Lines 207 to 234 in 9f114ae
You have to obtain the unminified production code that webpack passes to Terser in the failing case. |
I was mistaken. Terser defaults to using
|
Run
and post line 188444 from the file:
|
Thanks! I've found the issue. The output from angular pre-Terser with optimization=false is different. So I ran terser with --ecma=6 on the unminified output and found a trailing comma in a function call. Thanks for your help debugging. Now just to get the build optimizer working :) |
This may narrow down the build optimizer issue If you clone the repo in the issue, then run the following command
It hangs indefinitely |
That appears to be a typescript issue with parsing the file. That file is 19,000 plus lines with a large amount of deeply nested code blocks. Does the production build have sourcemaps enabled? Also of note, is that the library in question appears to be a NodeJS platform library and not a browser platform library. While this library can be made to work on a browser, there is a difference between working and actually targeting a particular platform. |
@clydin @filipesilva In the interest of making it easier to debug future minifier issues could this project add a new Also, consider setting the Terser |
Yes, it is a huge file. It is generated by PEG.js.
Nope
As far as I know, it is designed to work in the browser and node. I can't say libraries are my speciality, how does a single library go about targeting node and a browser? rather than just being made to work in both? The issue in question though (The build optimizer hanging) is only occurring on a single file. And that file doesn't contain any imports. So I don't think this one is a platform issue. I think you are correct on the typescript parsing. That seems to be where the issue is happening. So I guess the next step is to follow up with the typescript team? |
@RyanHow I have to start by saying that we don't provide support for custom configurations. You might feel like just changing the We don't test for custom configurations and our stance is that once you use a custom configuration it really is up to you to make it work. In this reproduction, removing the custom configuration causes the whole build to fail. Build Optimizer will spend an inordinate amount of time in the This probably needs a report to the typescript issue tracker, but the way we use TypeScript to parse every file is rather non-standard so I'm not sure something will come of it. You can see TypeScript hanging on that file by running Similar problems are #12153 and microsoft/TypeScript#17033. @kzc I'm not sure adding a At that point it's better to just go debug builds by fiddling with the webpack configs in I'm not sure I follow the argument for setting the But that doesn't change the fact that the build targets ECMA5 and that's invalid code in ECMA5. So I do think the build should fail. Code packaged in this way should only be used on builds targeting ECMA 8 or above, and the library should mention that. On the CLI side we infer the target ECMA version from the It's not easy to figure out where that invalid code is though. I did it by doing
This code block belongs to I think what the CLI should do in these cases is actually verify these things in advance and provide decent actionable information. Something like
We've been seeing more and more packaging/target ES problems as time goes by so this is definitely a growing problem. |
Thanks so much for the support and investigation despite the custom webpack config. I've logged an issue here too and we'll see how it goes. Would there be any simple workarounds in the interim apart from disabling the build optimizer? Regarding the library ECMA version, they've fixed the library so it is valid ES5, but we might not all be so lucky. It's easy to debug once you know how, but if it is possible for the CLI to give more informative output that would speed the process up a lot! Just a note: Apparently there were quite a few other ES6 issues in the library, but Terser was only complaining about that one. So if the idea was to run it through a linter or something else to pick up those issues, it may end up picking up more than it needs to? So it would need to use the Terser error to get the line number, but without source maps I'm not sure how you would reference it back to the source file? Anyway... I love the idea, and thanks so much for the support. |
@filipesilva Exactly - and that's a good thing. Hours are spent analyzing these types of issues to isolate the problem when a Anyway, I'm not an Angular user. It's your call.
As you've discovered, the ecma version parse checks in Terser are not comprehensive. When that particular trailing commas for call arguments feature was added the idea was to eventually add strict version checking for all language features. But it wasn't a high priority. Terser does have the ability to use Acorn as a parser for ES5 only. Acorn has strict parse checks for ecma versions. ESTree support for ES6+ is a work in progress in Terser. |
Thank you very much! I could find the problem in my code with your suggestion |
Hi
Third party library code example:
This is a set of web-components I'm trying to consume from angular, all of them using trailing commas in function parameters. Reference issue Unexpected token: punc ()) with comma after last param in func calls #412 |
@thematho I'm facing the same issue with the postprocessing library after upgrading to angular 8. |
Hi @martin31821 The first solution doesn't have support for angular 8 but the they are testing the next build to release it, you can try it from the branch check on the opened issues. |
I also have the same issue with npm --version Angular CLI: 8.3.4 devDependencies": { I was able to compile with ng build --prod --buildOptimizer=false --optimization=false Did you find a solution? |
For me, updating the dependency caused the problem worked, but the terser options builder should work as well |
Could you let me know which dependency did you updated? My package.json file is below and I think all the packages are updated. { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
sorry, maybe this is a stupid question. But has anyone actually been able to transpile es2015 in a lib only using the angular-cli? |
Thanks for reporting this issue. This issue is now obsolete due to changes in the recent releases. Please update to the most recent Angular CLI version. If the problem persists after upgrading, please open a new issue, provide a simple repository reproducing the problem, and describe the difference between the expected and current behavior. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug Report or Feature Request (mark with an
x
)Command (mark with an
x
)Versions
Repro steps
The above is a minimal repo imporing the @accordproject/cicero-core library.
It requires some custom webpack config. So it has @angular-builders/custom-webpack installed with
The log given by the failure
ng build --prod
hangs indefinitelyng build --prod --buildOptimizer=false
output an errorDesired functionality
I'd like to use the build optimization and optimizer. The bundle sizes are huge without them.
A workaround would be to exclude this library from optimization, or better, from specific forms of optimization causing the issue.
I've successfully used Terser in a react project importing this library, but I don't know what Angular CLI is doing under the hood to trigger the issue. So it is difficult to know where the issue is and what specific options are causing it. Verbose output doesn't really give any more info.
Mention any other details that might be useful
This is a repo with a minimal project
https://github.com/RyanHow/angular-cicero-build
The text was updated successfully, but these errors were encountered: