-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Bundle size reduction impossible through modular imports/dependencies #7839
Comments
You should never need to manually install the |
@iartemiev it isn't we do get about 15mb in total bundle size from 2 aws-amplify packages and 1 aws-sdk package. All we get from the console are warnings with this message:
|
I just reproduced this via:
Initial Chunk Files | Names | Size
vendor.js | vendor | 2.10 MB
polyfills.js | polyfills | 128.88 kB
main.js | main | 54.99 kB
runtime.js | runtime | 6.15 kB
styles.css | styles | 437 bytes
| Initial Total | 2.28 MB Then, I updated the app based on our docs:
diff --git a/.github/actions/bundle-size-action/angular/src/main.ts b/.github/actions/bundle-size-action/angular/src/main.ts
index 87454d40b..da16c6242 100644
--- a/.github/actions/bundle-size-action/angular/src/main.ts
+++ b/.github/actions/bundle-size-action/angular/src/main.ts
@@ -4,6 +4,12 @@ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
+import { Amplify, Auth } from 'aws-amplify';
+Amplify.configure();
+Auth.currentAuthenticatedUser()
+ .then(console.info)
+ .catch(console.warn);
+
if (environment.production) {
enableProdMode();
}
diff --git a/.github/actions/bundle-size-action/angular/src/polyfills.ts b/.github/actions/bundle-size-action/angular/src/polyfills.ts
index 5812bad0d..1e3100a58 100644
--- a/.github/actions/bundle-size-action/angular/src/polyfills.ts
+++ b/.github/actions/bundle-size-action/angular/src/polyfills.ts
@@ -54,6 +54,11 @@
*
*/
+(window as any).global = window;
+(window as any).process = {
+ env: { DEBUG: undefined },
+};
+
/***************************************************************************************************
* Zone JS is required by default for Angular itself.
*/
Initial Chunk Files | Names | Size
vendor.js | vendor | 14.33 MB
polyfills.js | polyfills | 128.88 kB
main.js | main | 55.13 kB
runtime.js | runtime | 6.15 kB
styles.css | styles | 437 bytes
| Initial Total | 14.52 MB
Build at: 2021-03-02T23:42:26.590Z - Hash: 2e22e0b09f82db47e3d8 - Time: 12985ms
Warning: ./node_modules/amazon-cognito-identity-js/es/utils/cryptoSecureRandomInt.js
Module not found: Error: Can't resolve 'crypto' in '/Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/amazon-cognito-identity-js/es/utils'
resolve 'crypto' in '/Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/amazon-cognito-identity-js/es/utils'
Parsed request is a module
using description file: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/amazon-cognito-identity-js/package.json (relative path: ./es/utils)
Field 'browser' doesn't contain a valid alias configuration
resolve as module So then I added Initial Chunk Files | Names | Size
vendor.js | vendor | 14.33 MB
polyfills.js | polyfills | 128.88 kB
main.js | main | 55.32 kB
runtime.js | runtime | 6.15 kB
styles.css | styles | 437 bytes
| Initial Total | 14.52 MB
Build at: 2021-03-02T23:43:55.093Z - Hash: 8b5b7efb0574e83235e7 - Time: 12730ms
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/@aws-amplify/auth/lib-esm/Auth.js depends on 'url'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/@aws-amplify/analytics/lib-esm/Providers/AWSPinpointProvider.js depends on 'uuid'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/@aws-amplify/datastore/lib-esm/datastore/datastore.js depends on 'uuid'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/amazon-cognito-identity-js/es/AuthenticationHelper.js depends on 'crypto-js/hmac-sha256'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/amazon-cognito-identity-js/es/AuthenticationHelper.js depends on 'crypto-js/lib-typedarrays'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/@aws-amplify/core/lib-esm/Signer.js depends on '@aws-crypto/sha256-js'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/amazon-cognito-identity-js/es/CookieStorage.js depends on 'js-cookie'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/@aws-amplify/analytics/lib-esm/Providers/AmazonPersonalizeProvider.js depends on 'lodash/isEqual'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/@aws-amplify/analytics/lib-esm/Providers/AmazonPersonalizeProvider.js depends on 'lodash/isEmpty'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/@aws-amplify/analytics/lib-esm/Providers/AmazonPersonalizeProvider.js depends on 'lodash/get'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/zen-observable-ts/lib/bundle.esm.js depends on 'zen-observable'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/@aws-amplify/storage/lib-esm/providers/axios-http-handler.js depends on 'axios'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/amazon-cognito-identity-js/es/Client.js depends on 'isomorphic-unfetch'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/@aws-sdk/eventstream-marshaller/dist/es/EventStreamMarshaller.js depends on '@aws-crypto/crc32'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/@aws-sdk/client-rekognition/dist/es/runtimeConfig.browser.js depends on '@aws-crypto/sha256-browser'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/@aws-sdk/client-s3/dist/es/protocols/Aws_restXml.js depends on 'fast-xml-parser'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
✨ Done in 17.06s. |
Oh wait. I'm not great with angular, but $ ng build --prod
✔ Browser application bundle generation complete.
✔ Copying assets complete.
✔ Index html generation complete.
Initial Chunk Files | Names | Size
main.2c551ec1947ae348ae65.js | main | 409.53 kB
polyfills.0890d7c9952feb894639.js | polyfills | 36.04 kB
runtime.7425f237727658da0a30.js | runtime | 1.45 kB
styles.3ff695c00d717f2d2a11.css | styles | 0 bytes
| Initial Total | 447.02 kB
Build at: 2021-03-03T00:53:47.844Z - Hash: fa80dd58a3a71734ee63 - Time: 24319ms
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/@aws-amplify/auth/lib-esm/Auth.js depends on 'url'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/@aws-amplify/analytics/lib-esm/Providers/AWSPinpointProvider.js depends on 'uuid'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/@aws-amplify/datastore/lib-esm/datastore/datastore.js depends on 'uuid'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/@aws-amplify/analytics/lib-esm/Providers/AmazonPersonalizeProvider.js depends on 'lodash/isEmpty'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/@aws-amplify/analytics/lib-esm/Providers/AmazonPersonalizeProvider.js depends on 'lodash/isEqual'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/@aws-amplify/analytics/lib-esm/Providers/AmazonPersonalizeProvider.js depends on 'lodash/get'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/amazon-cognito-identity-js/es/CookieStorage.js depends on 'js-cookie'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/@aws-amplify/storage/lib-esm/providers/axios-http-handler.js depends on 'axios'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/amazon-cognito-identity-js/es/AuthenticationHelper.js depends on 'crypto-js/hmac-sha256'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/amazon-cognito-identity-js/es/AuthenticationHelper.js depends on 'crypto-js/lib-typedarrays'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/amazon-cognito-identity-js/es/AuthenticationHelper.js depends on 'crypto-js/sha256'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/amazon-cognito-identity-js/es/CognitoUser.js depends on 'crypto-js/enc-base64'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/amazon-cognito-identity-js/es/Client.js depends on 'isomorphic-unfetch'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/@aws-sdk/eventstream-marshaller/dist/es/EventStreamMarshaller.js depends on '@aws-crypto/crc32'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/@aws-sdk/client-textract/dist/es/runtimeConfig.browser.js depends on '@aws-crypto/sha256-browser'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/@aws-sdk/client-s3/dist/es/protocols/Aws_restXml.js depends on 'fast-xml-parser'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/angular/node_modules/@aws-amplify/core/lib-esm/Signer.js depends on '@aws-crypto/sha256-js'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies (Adding https://gist.github.com/gsans/8982c126c4fef668c094ff288f04241b got rid of the errors.) For comparison, my vanilla app looks like: $ ng build --prod
✔ Browser application bundle generation complete.
✔ Copying assets complete.
✔ Index html generation complete.
Initial Chunk Files | Names | Size
main.9e5ef2589a32d22a3791.js | main | 134.96 kB
polyfills.9d7f1bb7deba7d27ca41.js | polyfills | 36.04 kB
runtime.7425f237727658da0a30.js | runtime | 1.45 kB
styles.3ff695c00d717f2d2a11.css | styles | 0 bytes @hentschelpatrick Can you use |
I migrated to angular 11.2.2 and tried it again: ✔ Browser application bundle generation complete.
it did help a lot, sadly we got introduced new errors from the migration. |
This seems to contradict some documentation / tutorials I've seen. Could you please link to where this is officially stated? |
@ChrisSargent The official documentation should be referencing
If this isn't the case, let us know so we can update it 🙏 |
Okay - I'll keep an eye open and open a ticket if I find some again. Perhaps it was in older tutorials on the blog. |
FYI, I swapped to having all my imports the way you recommended and my bundle size went from 601kb to 642kb - a not-insignificant increase to an already huge bundle size from the Auth module, relating to this issue: #7570 |
This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs. Looking for a help forum? We recommend joining the Amplify Community Discord server |
Describe the bug
We are trying to reduce the bundle size be refactoring the aws-amplify package to it's modular components.
Everything worked fine until we deleted the
aws-amplify
package at the last step and added the@aws-amplify/api-graphql
package.To Reproduce
To reduce the huge bundle size we are refactoring to modular imports from the aws-amplify package.
As original dependency we had:
and I could refactor it to:
when deleting the package
aws-amplify
and replacing it by:@aws-amplify/api-graphql
as the modular dependency for the API calls the following import signatures in the API Service changed:to
Expected behavior
The angular app continues working
Code Snippet
Screenshots
Error when the application calls the GraphQL API from AWS
What is Configured?
Environment
The text was updated successfully, but these errors were encountered: