Aggregating Javascript files breaks JS On my d8 site I have AdvAgg CSS/JS Validator, AdvAgg Minify CSS, AdvAgg Minify JavaScript, AdvAgg Modifier and Advanced CSS/JS Aggregation enabled.

I have standard settings used in the AdvAgg config. For JS specifically, I am using JSmin + and delivering gzip'd assets.

Under admin/config/development/performance, if Aggregate JavaScript files is unchecked, my JS files are delivered from the js/optimized/ folder and JS runs correctly. When I check Aggregate JavaScript files on, assets are now placed from /js/ and javascript is broken. 

Further, when I paste the optimized file name in admin/config/development/performance/advagg/info, for e.g.: js_nrTZ3IQttmDSsRueLl0pyxRvunHefp0r1WyIh5cFezg.js AdvAgg cannot find the file (but it can when aggregation is turned off). 

Perhaps this all makes sense since aggregating JS files is a Drupal feature, but I've been down every related question/comment thread on google (changing .htaccess, adding tmp folders, changing folder permissions etc) and cannot find a fix for: AdvAgg is on with standard config, Aggregating JS files is on and javascript is broken. There are no obvious errors in the javascript console or drupal error log either.

EDIT

Here is what the file paths look like with aggregation on:
&lt;script src="/sites/energyforum/files/js/js_tvBcOK6c8zbgb2_h2fxvH7fqhBBhGUnfOtQvWyXg1AM.js"&gt;&lt;/script&gt;

The files are actually there, e.g.:


Here is what they look like with aggregation turned off

&lt;script src="/sites/energyforum/files/js/optimized/js_dxIVcwvQ00owLGoUGPTfRYXU-T5rnj8Xi0cXfb3Kn58.0EvW5goc0mi1CLAZ226j56yYkdNjFXiaCYoOaoBMbKg.js?v=3.2.1"&gt;&lt;/script&gt;

And, of course, there are many more of them (and javascript works)
This is commonly a result of loading theme javascript before it's dependencies. 

If your theme lists multiple external js dependencies, or just has multiple custo. Javascript files, you may need to assign weights to establish a load order. Refer to
https://www.drupal.org/docs/8/theming/adding-stylesheets-css-and-javascript-js-to-a-drupal-8-theme

Likewise, if your theme depends on other javascript provided by other modules, be sure to list those dependencies in your theme.info.yml file.

After making any of the above changes, clear Drupal caches with aggregation turned on and retest.