I've updated an Angular project from version 7 to 8. Everything runs smoothly, schematics did it's job (maybe) and we are Ok (project is even in production). When we're updating Angular CLI, we always generate a new project to see the real differences and learn from them such as new dependencies, configurations, etc.
When generating a new Angular project with Angular CLI 8.0.4, the new app doesn't have core-js
as dependency:
"dependencies": { "@angular/animations": "~8.0.1", "@angular/common": "~8.0.1", "@angular/compiler": "~8.0.1", "@angular/core": "~8.0.1", "@angular/forms": "~8.0.1", "@angular/platform-browser": "~8.0.1", "@angular/platform-browser-dynamic": "~8.0.1", "@angular/router": "~8.0.1", "rxjs": "~6.4.0", "tslib": "^1.9.0", "zone.js": "~0.9.1" }
Analyzing bundle on built project core-js
is not there: On my older project, updated with Angular CLI, core-js
is there and is present in the final bundle:
"dependencies": { "@angular/animations": "~8.0.3", "@angular/cdk": "~8.0.1", "@angular/common": "~8.0.3", "@angular/compiler": "~8.0.3", "@angular/core": "~8.0.3", "@angular/forms": "~8.0.3", "@angular/platform-browser": "~8.0.3", "@angular/platform-browser-dynamic": "~8.0.3", "@angular/router": "~8.0.3", "@auth0/angular-jwt": "2.1.1", "@hackages/ngxerrors": "~8.0.0", "@ng-bootstrap/ng-bootstrap": "5.0.0-rc.1", "@ngx-loading-bar/core": "~4.2.0", "@ngx-loading-bar/http-client": "~4.2.0", "@nicky-lenaers/ngx-scroll-to": "~2.0.0", "@swimlane/ngx-charts": "~12.0.1", "bootstrap": "~4.3.1", "core-js": "~2.6.9", "d3-scale": "~3.0.0", "d3-shape": "~1.3.5", "date-fns": "2.0.0-beta.2", "ngx-perfect-scrollbar": "~8.0.0", "ngx-toastr": "~10.0.4", "rxjs": "~6.5.2", "tslib": "~1.10.0", "xlsx": "~0.14.3", "zone.js": "~0.9.1" }
Why is this behavior? Is it safe to remove core-js
as dependency? Does update schematics missing this? When installing npm
dependencies on the newest project I get the post-install messages from core-js
, but it is not explicitly present in package description.
Angular CLI 8.0+ manages the required Angular polyfills directly and projects will not require a direct dependency on core-js (assuming an application does not manually include additional core-js polyfills).
The Core JavaScript Framework or "CoreJS" is a client-side JavaScript library which provides tools for creating object-oriented and event-driven JavaScript code. It is used by the Echo3 Framework but is not in any way dependent upon it (CoreJS is designed be used independently).
Angular CLI has removed core-js from the installed dependencies when creating a project as those are handled via the differential polyfilling. Additionally, they've also bumped their use of it to the next major version ( ^3.0. 0 ) internally. As part of upgrading to Nx 8, perhaps something similar needs to happen.
Polyfills in angular are few lines of code which make your application compatible for different browsers. The code we write is mostly in ES6(New Features: Overview and Comparison) and is not compatible with IE or firefox and needs some environment setups before being able to be viewed or used in these browsers.
According to this article.
Note that core-js has been updated to v3, and is now directly handled by the CLI itself, so it’s no longer needed as a dependency of your application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With