You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Angular 6 - Prod build fails with property 'call' of undefined in runtime.js #11129
After lots of trials and errors and lots of googling I think I solved my problem but the potential solution goes well beyond my understanding and knowledge of angular ...
Couldn't understand why for a clean project "ng build --prod" works fine while for my project not but it looks like generating the build with:
"ng build --prod --source-map"
does the trick.
Can't really figure out how --source-map affects the building process for one or more of the packages that generated the error in runtime.js but it seems to work.
Just going to investigate a bit more about that (in order to understand if that is really THE solution) before closing the issue.
unfortunately couldn't find the exact cause and gave it up (... already feeling lucky enough to have been able to generate a running production build using the "--source-map" trick)
I'm sure that it has something to do with one or more third-party packages that are installed in the app so I think the best way to isolate the problem would be to create a new empty application and to monitor the generated prod bundle while progressively adding all the third-party packages related to your specific app one at a time.
Anyhow even if I found it I already know I couldn't understand why it breaks the build (as far as I know runtime.js should be independent from your own code) since my code worked without any problem with angular 5 (... some days ago I had the pretty bad idea of upgrading to version 6 because I needed the latest Angular Material version).
I'm reopening the issue in case anyone else is experiencing the same problem or can make any contribution to solve it.
I've bisected the issue in my project and it started happening for me since I updated it to use the RxJS 6 import syntax instead of the old v5 one. This was mostly stuff like:
-import { merge } from 'rxjs/observable/merge';+import { merge } from 'rxjs';
and:
-import { pairwise } from 'rxjs/operators/pairwise';-import { filter } from 'rxjs/operators/filter';-import { take } from 'rxjs/operators/take';+import { pairwise, filter, take } from 'rxjs/operators';
that's really bad ... that means the build could fail again anytime even in my case ...
@mgol thanks for pointing out the rxjs issue.
Until now I thought it was something related to one of the packages I've added for my app but In my case too I had to replace all the import stuff from rxjs with the new syntax when upgrading.
Given that I haven't tried yet generating an empty app (for which --prod works) but with some rxjs stuff that could be the problem.
Maybe it's worth trying ... I'll give it a try and report about it in a while.
ng build --prod --optimization=false
nice ... never tried it before but I agree with @mgol, it may have something to do with the uglifier
added a simple module (extracted from a project for which --prod not working) made of a service wrapping angular's httpclient with some rxjs stuff ( such as the retry operator )
Result: --prod working as expected
At least for me rxjs is not the problem but (given that ng build works) I'm convinced that uglifyjs (or the minifier as well) could be the problem as pointed out by @mgol
I checked all the options of the ng build but as far as I can see there's no way to enable/disable the uglifier alone, it seems to be "glued" to the optimizer as a whole ...
I've tried --optimization=false again on a different commit (with & without --source-map) and it didn't help there. :/ This seems to be pretty random...
EDIT: Sorry, my bad, I was invoking a wrong command. --optimization=false still helps.
@Ludevik in your case if you remove the enums you found the production bundle works? Just trying to figure out all the possible scenarios for which it fails ...
Yes, --optimization=false generates a working app but unfortunately I don't see any difference with ng build (without any option): output files have a similar (big) size probably due to the optimization process not invoked (but that wouldn't be a big problem after all) and the app is relatively slow when running (I suspect that with --optimization=false angular still performs all double checkings while running as if it was running during development).
So far in my case the best I can get is with --prod --source-map which generates a bundle even smaller than with --prod alone (roughly 10% smaller) and fast enough when running to be regarded as a production build, but I can't really figure out why it works (and unfortunately why it doesn't work for you ...)
Here is another trial (suggested here and there for problems related to uglifyjs): change "target" key of your "compilerOptions" of tsconfig.js from "es5" to "es2015".
In my case (with ng build --prod)it solved the problem of runtime.js but gave me other problems in main.js related to the need for calling super() here and there ...
I have this issue even with the latest dependencies. Turning off optimization fixes it. This started happening when I moved a large (non-angular) library outside of my project, bundled it with webpack, and added it as dependency to my application.
edit1: I have a suspicion it has something to do with reflect-metadata that my bundled library depends on due to class-transformer
edit2: I'm not so sure about that suspicion now because the angular compiler itself relies on reflect-metadata. The core-js polyfill provides it's own reflect metadata functionality so maybe there's a conflict but I doubt that's an issue for AOT because a comment in my pollyfill.ts says it can be removed for AOT. Removing it didn't solve the issue.
I had similar event-related issues when hovering on plots using plot.ly: `ERROR TypeError: "o[a] is undefined".
As some of you noticed, the --optimization=false is still generating quite a big bundle. It turns out that --build-optimizer=false also solved the problem in my case. But it generates a way smaller bundle than with the full optimization removed so that's great! I haven't found a clear definition of what optimization does but as i understand it, it's super set of parameters including build-optimizer, which removes the dead code through Tree shaking if i understand it right.
Still these are workarounds and the problem has to be fixed to allow all flags to work as expected.
Thank you for the tip, @virgile-hogman, it sounded like a good idea. However, for our project it did not work. The only change that did help, was to remove all optimization, which resized our main bundle from 600 KB to 5 MB.
For info, the issue i had when hovering on plots in prod mode is now solved!
This problem appeared with a fully optimized bundle, consisting of two parameters: optimization (minimizer) + buildOptimizer (tree shaking), which are enabled by default in prod mode, at least with Angular 7.
As stated here a few months ago, I had to turn the buildOptimizer off to make the application work, but now i can also enable it again and i'm convinced the solution came with a fix on the build of angular-plotly.js. At least it's the most rational explanation, as a double minimization (of the underlying plotly.js library) created some strange issues already with the minimizer step alone.
Now i have a fully optimized bundle, so that's great! :)
In short, maybe the cause is different, but check if you don't have some double minimization going on through your third-party dependencies, that could explain some issues with the prod mode.
I had the same issue with the angular-plotly library. The point looked to be the fact that this library was already calling a minified library (plotly.js in that case) and the double minification was the origin of the problem. The new version (1.0) of angular-plotly solved perfectly the issue. I hope that might help somebody...
Reacted by MD Ashik
angular-automatic-lock-bot commented on Sep 9, 2019
Activity
marcotoldo commentedon Jun 7, 2018
After lots of trials and errors and lots of googling I think I solved my problem but the potential solution goes well beyond my understanding and knowledge of angular ...
Couldn't understand why for a clean project "ng build --prod" works fine while for my project not but it looks like generating the build with:
"ng build --prod --source-map"
does the trick.
Can't really figure out how --source-map affects the building process for one or more of the packages that generated the error in runtime.js but it seems to work.
Just going to investigate a bit more about that (in order to understand if that is really THE solution) before closing the issue.
Ludevik commentedon Jun 11, 2018
@marcotoldo Hi, did you find the cause? I am experiencing currently the same problem.
marcotoldo commentedon Jun 11, 2018
Hi @Ludevik
unfortunately couldn't find the exact cause and gave it up (... already feeling lucky enough to have been able to generate a running production build using the "--source-map" trick)
I'm sure that it has something to do with one or more third-party packages that are installed in the app so I think the best way to isolate the problem would be to create a new empty application and to monitor the generated prod bundle while progressively adding all the third-party packages related to your specific app one at a time.
Anyhow even if I found it I already know I couldn't understand why it breaks the build (as far as I know runtime.js should be independent from your own code) since my code worked without any problem with angular 5 (... some days ago I had the pretty bad idea of upgrading to version 6 because I needed the latest Angular Material version).
I'm reopening the issue in case anyone else is experiencing the same problem or can make any contribution to solve it.
mgol commentedon Jun 11, 2018
I've had the same issue but for me adding
--source-mapdoesn't help...Ludevik commentedon Jun 11, 2018
Same for me, --source-map doesn't help, but at least i see the culprit, it is one of my exported enums from my library.
mgol commentedon Jun 11, 2018
I've bisected the issue in my project and it started happening for me since I updated it to use the RxJS 6 import syntax instead of the old v5 one. This was mostly stuff like:
and:
I've also discovered that calling:
works as well. May it be an UglifyJS issue?
marcotoldo commentedon Jun 11, 2018
that's really bad ... that means the build could fail again anytime even in my case ...
@mgol thanks for pointing out the rxjs issue.
Until now I thought it was something related to one of the packages I've added for my app but In my case too I had to replace all the import stuff from rxjs with the new syntax when upgrading.
Given that I haven't tried yet generating an empty app (for which --prod works) but with some rxjs stuff that could be the problem.
Maybe it's worth trying ... I'll give it a try and report about it in a while.
nice ... never tried it before but I agree with @mgol, it may have something to do with the uglifier
marcotoldo commentedon Jun 11, 2018
Just tested out rxjs (cli 6.0.7):
Result: --prod working as expected
At least for me rxjs is not the problem but (given that ng build works) I'm convinced that uglifyjs (or the minifier as well) could be the problem as pointed out by @mgol
I checked all the options of the ng build but as far as I can see there's no way to enable/disable the uglifier alone, it seems to be "glued" to the optimizer as a whole ...
mgol commentedon Jun 11, 2018
I've tried--optimization=falseagain on a different commit (with & without--source-map) and it didn't help there. :/ This seems to be pretty random...EDIT: Sorry, my bad, I was invoking a wrong command.
--optimization=falsestill helps.marcotoldo commentedon Jun 11, 2018
@mgol :-(
@Ludevik in your case if you remove the enums you found the production bundle works? Just trying to figure out all the possible scenarios for which it fails ...
mgol commentedon Jun 11, 2018
@marcotoldo Could you try to add
--optimization=falseto your app in a version that has this issue and see if it helps?marcotoldo commentedon Jun 11, 2018
@mgol thanks, just gave it a try.
Yes, --optimization=false generates a working app but unfortunately I don't see any difference with
ng build(without any option): output files have a similar (big) size probably due to the optimization process not invoked (but that wouldn't be a big problem after all) and the app is relatively slow when running (I suspect that with--optimization=falseangular still performs all double checkings while running as if it was running during development).So far in my case the best I can get is with
--prod --source-mapwhich generates a bundle even smaller than with--prodalone (roughly 10% smaller) and fast enough when running to be regarded as a production build, but I can't really figure out why it works (and unfortunately why it doesn't work for you ...)Here is another trial (suggested here and there for problems related to uglifyjs): change "target" key of your "compilerOptions" of tsconfig.js from "es5" to "es2015".
In my case (with
ng build --prod)it solved the problem of runtime.js but gave me other problems in main.js related to the need for calling super() here and there ...marcotoldo commentedon Jun 11, 2018
sorry ... according to cli official doc:
so target "es2015" cannot be used with --prod
10 remaining items
filipesilva commentedon Aug 10, 2018
Fixed via #11488, we shouldn't have a dependency on
4.10.2in our latest versions anymore.Leanvitale commentedon Aug 16, 2018
Try for this..
sparebytes commentedon Oct 3, 2018
edit3: Updating to Angular 7 RC fixed it. See my other comment below.
I have this issue even with the latest dependencies. Turning off
optimizationfixes it. This started happening when I moved a large (non-angular) library outside of my project, bundled it with webpack, and added it as dependency to my application.edit1: I have a suspicion it has something to do with
reflect-metadatathat my bundled library depends on due to class-transformeredit2: I'm not so sure about that suspicion now because the angular compiler itself relies on
reflect-metadata. Thecore-jspolyfill provides it's own reflect metadata functionality so maybe there's a conflict but I doubt that's an issue for AOT because a comment in mypollyfill.tssays it can be removed for AOT. Removing it didn't solve the issue.package.json:
yarn.lock
sparebytes commentedon Oct 3, 2018
Encouraging news. Updating to angular version
7.0.0-rc0and corresponding versions for@angular-devkitand@angular/clifixed it! :)package.json
EzraBrooks commentedon Oct 30, 2018
I'm still experiencing this issue as of CLI 7.0.3.
virgile-hogman commentedon Oct 30, 2018
I had similar event-related issues when hovering on plots using plot.ly: `ERROR TypeError: "o[a] is undefined".
As some of you noticed, the
--optimization=falseis still generating quite a big bundle. It turns out that--build-optimizer=falsealso solved the problem in my case. But it generates a way smaller bundle than with the fulloptimizationremoved so that's great! I haven't found a clear definition of whatoptimizationdoes but as i understand it, it's super set of parameters includingbuild-optimizer, which removes the dead code through Tree shaking if i understand it right.Still these are workarounds and the problem has to be fixed to allow all flags to work as expected.
pszalanski commentedon Dec 11, 2018
Thank you for the tip, @virgile-hogman, it sounded like a good idea. However, for our project it did not work. The only change that did help, was to remove all optimization, which resized our main bundle from
600 KBto5 MB.Angular version was updated today to
7.1.2.Does anyone have any other ideas?
virgile-hogman commentedon Jan 15, 2019
For info, the issue i had when hovering on plots in prod mode is now solved!
This problem appeared with a fully optimized bundle, consisting of two parameters:
optimization(minimizer) +buildOptimizer(tree shaking), which are enabled by default in prod mode, at least with Angular 7.As stated here a few months ago, I had to turn the
buildOptimizeroff to make the application work, but now i can also enable it again and i'm convinced the solution came with a fix on the build of angular-plotly.js. At least it's the most rational explanation, as a double minimization (of the underlying plotly.js library) created some strange issues already with the minimizer step alone.Now i have a fully optimized bundle, so that's great! :)
In short, maybe the cause is different, but check if you don't have some double minimization going on through your third-party dependencies, that could explain some issues with the prod mode.
julkwel commentedon Mar 7, 2019
--build-optimizer=falsework for me ,--optimization=falsedidn't workinfrarosso78 commentedon Apr 16, 2019
I had the same issue with the angular-plotly library. The point looked to be the fact that this library was already calling a minified library (plotly.js in that case) and the double minification was the origin of the problem. The new version (1.0) of angular-plotly solved perfectly the issue. I hope that might help somebody...
angular-automatic-lock-bot commentedon Sep 9, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.