Skip to content

Build Optimizer does not support es2015 code #12112

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

Closed
alexeagle opened this issue Sep 4, 2018 · 40 comments
Closed

Build Optimizer does not support es2015 code #12112

alexeagle opened this issue Sep 4, 2018 · 40 comments
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@alexeagle
Copy link
Contributor

From @filipesilva on April 30, 2018 17:28

Build Optimizer does not currently support es2015 modules code, but we should support it.

Related to angular/devkit#237

Copied from original issue: angular/devkit#816

@alexeagle
Copy link
Contributor Author

From @robwormald on May 4, 2018 18:43

Should also support ES2015 code (really, it should support esnext)

@alexeagle
Copy link
Contributor Author

From @hansl on May 5, 2018 19:5

I was under the impression UglifyES (or whatever NG version of uglify) was doing a proper job at DCE on ES2015 code and that we wouldn't need build optimizer for those.

@alexeagle
Copy link
Contributor Author

From @cyrilletuzi on May 8, 2018 9:43

Note: now we have Angular Elements, support for ES2015 becomes more important, because transpiling custom elements to ES5 is not supported by the standard and produces an error.

@alexeagle
Copy link
Contributor Author

From @rafaelfgx on May 10, 2018 23:59

With all the respect, this is a very basic bug and one that should be avoided.

You create an Angular 6 application, without changing anything, with all the default settings, build it for production, and it does not work.

It is very serious that something so trivial as publishing in production is not working in the final version.

More testing is needed, especially for the most important and essential tasks.

@alexeagle
Copy link
Contributor Author

From @robwormald on May 11, 2018 0:34

@rafaelfgx - nobody should be using es2015 modules in production, Webpack doesn’t export them, and they’re not turned on by default.

@alexeagle
Copy link
Contributor Author

From @msklvsk on May 11, 2018 9:22

While buildOptimizer is turned on by default, es6 is not, including the docs:

image

(angular.io/guide/typescript-configuration)

@alexeagle
Copy link
Contributor Author

From @devoto13 on May 14, 2018 12:24

@hansl It does not seem to be the case.

Here is ES2015 with build optimizer on (fails with #10658):

screenshot 2018-05-14 13 56 39

Here is ES2015 with build optimizer off:

screenshot 2018-05-14 14 14 36

As you can see it is ~200k less with build optimizer enabled. Not sure if it is real gain or a side effect of build optimizer removing not dead code, but this looks like a lot of gain. Most of it comes from Angular packages (~180k).

@alexeagle
Copy link
Contributor Author

From @catull on May 16, 2018 12:43

Hmm, I see a build optimiser bug for production builds with ES5.

See #7799 (comment).
That issue is closed, stating that the bug is tracked here.

As a work-around, I switched off build-optimiser and the app is working.
With build-optimiser ON, the error is as documented in the "issue comment" at the top of this comment.

@alexeagle
Copy link
Contributor Author

From @hijamoya on May 17, 2018 10:17

I got same issues here.

@alexeagle
Copy link
Contributor Author

From @byrondover on May 27, 2018 20:27

robwormald commented 10 days ago

@rafaelfgx - nobody should be using es2015 modules in production, Webpack doesn’t export them, and they’re not turned on by default.

@robwormald You may want to align with @StephenFluin on your community messaging around enabling ES2015. 😅

https://twitter.com/stephenfluin/status/997224523610116096

P.S. Big fans of all the work you do and are doing! 🤞for production ES2015 support by 2020. :neckbeard:

@alexeagle
Copy link
Contributor Author

From @robwormald on May 27, 2018 20:51

@byrondover ES2015 syntax (classes, const,let,etc) is fine (assuming your browser target supports it) - lots of good wins to be had there.

ES2015 modules, not so much (though if you a very adventurous, no harm trying)

@alexeagle
Copy link
Contributor Author

From @StephenFluin on May 27, 2018 21:25

My talk was about how Angular is working to push the limits of the web, and that if/when it made sense to ship all apps as ES2015 we could do that for you and save a bunch of bundle size and increase perf. Hello World worked for me but in general shipping ES2015 actually can hurt your machine readability as things like the Google crawler don't support ES2015

@alexeagle
Copy link
Contributor Author

From @byrondover on May 27, 2018 21:59

Wow, didn't expect a response, let alone over Memorial Day weekend. 🇺🇸

Thanks for the clarification, gents! 🙇

@alexeagle
Copy link
Contributor Author

From @zijianhuang on May 28, 2018 5:29

Having this problem since NG 6.0. Still a problem in 6.0.3 along with the latest CLI. As said by this others, setting "buildOptimizer":false will make things in production work again, however, the bundle is apparently too big. Let's see if 6.0.4 will has this fixed?

@alexeagle
Copy link
Contributor Author

From @TomDemulierChevret on May 28, 2018 7:32

@StephenFluin Having our webapp crawlable is not mandatory for many of us. In my company 90% of Angular apps we develop are not publicly available.

@robwormald Is it possible to build with only ES2015 syntax ?

@alexeagle
Copy link
Contributor Author

From @filipesilva on May 29, 2018 13:8

angular/devkit#981 has some fixes for ES2015 code support.

Thinking more about it, I don't think we do anything in regards to ES2015 modules in Build Optimizer, so that is probably enough.

@alexeagle
Copy link
Contributor Author

From @filipesilva on May 30, 2018 9:47

Building upon #981, we should also wrap static initializers on ES2015 classes.

This is similar to https://github.com/angular/devkit/blob/master/packages/angular_devkit/build_optimizer/README.md#wrap-enums.

The following TS class:

class MyClass {
  static field = console.log('hello');
}

transpiled to es2015 is:

"use strict";
class MyClass {
}
MyClass.field = console.log('hello');
//# sourceMappingURL=static.js.map

and ran through build optimizer yields:

"use strict";
class MyClass {
}
MyClass.field = /*@__PURE__*/ console.log('hello');

MyClass can never be dropped because of the property access. If we wrap it it should be ok though:

var MyClass = (function () {
  class MyClass {
  }
  MyClass.field = console.log('hello');
  return MyClass;
})();

@alexeagle
Copy link
Contributor Author

From @clydin on May 30, 2018 14:6

Two potential downsides to this approach would be increased code size and a potential decrease in runtime performance. Both of these should be analyzed to ensure the additional behavior is a net positive.

@alexeagle
Copy link
Contributor Author

From @zijianhuang on May 31, 2018 3:55

As of Angular CLI 6.0.7, the problem is still there.

@alexeagle
Copy link
Contributor Author

From @filipesilva on May 31, 2018 7:39

@zijianhuang the changes are not in 6.0.7. I think you can test these changes by installing @angular-devkit/[email protected].

@alexeagle
Copy link
Contributor Author

From @Maximaximum on May 31, 2018 7:45

I updated @Angular-devkit to 0.6.7 and the issue seems to be gone.

@alexeagle
Copy link
Contributor Author

From @cedvdb on June 5, 2018 10:12

issue still here with 0.7.0 and target es6.

What would be really nice is an error at compilation time as to maybe find a temporary fix for the part of the code that's problematic.

@alexeagle
Copy link
Contributor Author

From @filipesilva on June 5, 2018 12:58

@cedvdb can you put up a repro I can look at please?

@alexeagle
Copy link
Contributor Author

From @cedvdb on June 6, 2018 12:46

@filipesilva

The problem seems to be resolved. I didn't manage to reproduce it yet. If you need so I could dig deeper this evening, right now I gotta work.

@alexeagle
Copy link
Contributor Author

From @filipesilva on June 6, 2018 12:51

As long as it's working, I think there's no need to look further. If I had to bet it wasn't working because at some point you were in an old version.

This fix is only on @angular-devkit/[email protected] that comes with @angular-devkit/[email protected].

You can check what version you have with npm list @angular-devkit/build-optimizer.

@alexeagle
Copy link
Contributor Author

From @shahafal on June 6, 2018 13:40

@StephenFluin ... things like the Google crawler don't support ES2015

thank you for this, it's the first time i'm hearing of it. unfortunately except for discussions about this being an issue i can't find anywhere a discussion about the status to fix this.
do you know if there is an open thread in github (or someplace else) discussing the fix? i would like to follow it

@filipesilva filipesilva added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent and removed priority2: required labels Sep 7, 2018
@filipesilva
Copy link
Contributor

Build Optimizer should now not break ES2015 code.

It still doesn't have certain desirable features such as #13487 or #13488, but those are being tracked in their respective issues.

@VVKot
Copy link

VVKot commented Feb 12, 2019

@filipesilva Greetings! Does "now" mean angular-cli 8+?

@filipesilva
Copy link
Contributor

@VVKot it should be in 7.3 too, the latest fixes we had were released in https://github.com/angular/angular-cli/releases/tag/v7.3.0-rc.0.

@ryshep111
Copy link

The issue is still present for me on version 7.3.7

@filipesilva
Copy link
Contributor

@ryshep111 can you open a new issue including a reproduction? I'm don't really know what you're seeing or how to investigate it.

@zijianhuang
Copy link

@ryshep111, the issue was fixed somewhere after v6.0.3, at the moment I am using v7.2.12.
my tsconfig.json:

{
	"compileOnSave": false,
	"compilerOptions": {
		"baseUrl": "./",
		"outDir": "./dist/out-tsc",
		"sourceMap": true,
		"declaration": false,
		"moduleResolution": "node",
		"emitDecoratorMetadata": true,
		"experimentalDecorators": true,
		"target": "es2015",
		"typeRoots": [
			"node_modules/@types"
		],
		"lib": [
			"es2017",
			"dom"
		],
		"skipLibCheck": true
	}
}

My angular.json

...
					"configurations": {
						"production": {
							"optimization": true,
							"outputHashing": "all",
							"sourceMap": false,
							"extractCss": true,
							"namedChunks": false,
							"aot": true,
							"extractLicenses": true,
							"vendorChunk": false,
							"buildOptimizer": true,
							"fileReplacements": [
								{
									"replace": "src/environments/environment.ts",
									"with": "src/environments/environment.prod.ts"
								}
							],
							"serviceWorker": true
						}
					}
...

Hope this gives you some hint.

@shlomiassaf
Copy link

@alan-agius4 @filipesilva

OK, it took me 4 hours but I think I found the root cause, or at least the way to reproduce exactly.

I've created a repository to reproduce it, all explanations are in the readme file there.

https://github.com/shlomiassaf/angular-cli-build-optimizer-es2015-issue

Ohh boy, this one was tricky.

TLDR: It will only happen if the class is built in FESM2015 module AND it has a NON-ANGULAR decorator applied on it.

I.E: Angular packages built with ng-packger.

@waterplea
Copy link

waterplea commented Jul 12, 2019

@shlomiassaf it reproduces for me too. In our library we have our own decorators so it's probably the same root cause — all our super calls are dropped with build optimizer and es2015 target. Works fine in Angular 8 though. @filipesilva any chance this could be fixed in Angular 7 by investigating the above reproduction repo? Could we at least somehow mark super calls so compiler does not cut them out? This looks like the only problem we are having.

@filipesilva
Copy link
Contributor

@waterplea I think it got fixed in #14263. In general we don't do releases of n-1 versions unless it's a security concern though. Is there something stopping you for updating to version 8?

@waterplea
Copy link

@filipesilva I'm developing a library which theoretically works in Angular 6+, it's just unfortunate that if users would want to run my library in es2015 they are forced to update. So yeah, I understand you not touching older versions, I was maybe hoping for some ninja tactics like // @dynamic or whatever :)

@maxim1006
Copy link

@VVKot it should be in 7.3 too, the latest fixes we had were released in https://github.com/angular/angular-cli/releases/tag/v7.3.0-rc.0.

No it is not working in 7.3

@maxim1006
Copy link

#14263

Hello

Why this issue is closed?

In any v7 version, with ng library, you can reproduce this issue.

In my company we cant update to v8 instantly.

@Stevearzh
Copy link

Well, is there something I can do to solve this on v6.2.9? We can't update (trying) to v8 like upstairs.

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

No branches or pull requests

9 participants