-
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
Adding Amplify Auth to a Next.js project has a huge impact of the chunk size #7570
Comments
Dumping the amplify package might help, see #7313 (comment) |
This looks to be related to #7521, which has been merged but not released yet. We will likely be doing a release this week. However, you can test out the changes currently in |
I just tested using I also tried with |
Ah yes, sorry, I forgot that the PR only addressed a usage with Create React App. I'll do a bit more digging and testing and get back to you 👍 |
We definitely need to investigate this more, particularly for Next.js. Next.js is moving to support Webpack 5, but explicitly adds a polyfill for Next.js' "base bundle" size is around We'd like to get this lower, of course, knowing that we don't want |
I just tried |
This is also a big issue for us as our bundle size has increased dramatically. |
Confirming this is also an issue with latest |
Has there been any progress or update on this issue? This issue is really slowing down our site. Alternatively, is there documentation on how to use Cognito without Amplify? |
Any updates? |
Same issue, amplify is absolutely unusable with next.js with first load of The same module gets loaded like 8 times. Can we get an update from the amplify team, I mean this is not really a corner case issue, Next.js is one of the most popular react frameworks. Is this being worked on? The amplify team say they're working on deploying next.js applications using amplify, I mean that's great and very exciting, but maybe a priority should be to not load over 300kb of gzipped code for the auth module. Also didn't realize about this until I finished building the site, that's not very fun. |
I'm curious if there are any updates to this.I think it's safe to say that using Nextjs to create Jamstack is now the standard.This is a pretty important issue. |
Words cannot explain how continuously disappointed I am with the Amplify team's lack of responses on a wide net of outstanding issues such as this one. |
Hey everyone, I'm personally sorry for the late resolution here. With bundle sizes improved via #7521, I missed that Next.js doesn't resolve I opened a PR with my research, tests to alert us on bundle-size increases (so bloat doesn't happen accidentally), and possible solutions. I'd really appreciate your input here: For an immediate workaround, you can opt-in to the --- a/samples/next/auth/ssr-auth/next.config.js
+++ b/samples/next/auth/ssr-auth/next.config.js
@@ -1,3 +1,8 @@
module.exports = {
target: 'serverless',
+ webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
+ config.resolve.extensions = ['.web.js', ...config.resolve.extensions]
+
+ return config
+ },
} The results are:
Down to 142kB from 281kB (-138kB). For comparison, Next.js has a ~65kB "tax" just to run "Hello World". This puts the I also created a Bundle Size Optimizations milestone to track these issues & get them released once we validate Next.js + Amplify continues working as intended 🙏 |
@ericclemmons I’m grateful for all your help |
Hi @ericclemmons, thanks for sharing this. Do you have any ideas as to why this solution wouldn’t work with other react frameworks? I created a brand new Gatsby project and added Auth as a dependency, and also configured webpack to resolve .web.js files, but am still seeing the crypto polyfills included in the bundle. Dependency in package.json:
Importing Auth in gatsby-browser.js:
Configuring webpack in gatsby-node.js:
However, as you can see from the bundle analyser output, all those crypto modules are still being included: Any ideas as to how to exclude them? Thanks |
@izzy-h I'm looking into By default, I get: warn Module not found: Error: Can't resolve 'crypto' in '/Users/ecclemm/Projects/ericclemmons/amplify-js/.github/actions/bundle-size-action/gatsby/node_modules/amazon-cognito-identity-js/es/utils'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
- install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "crypto": false } If you could provide a working Gatsby repo with |
Can part of that deeper dive mentioned above include figuring out why using the |
btw.. the same happens if you are using NuxtJS. |
Hey, is there any update on this? I'm using nextjs 12 with aws-amplify and aws-amplify-react (for Authenticator), and it adds 150kb to the first load. Is there anything that I can do to reduce that? |
I have the same problem reported by riceboyler: @aws-amplify/core, @aws-amplify/API/Storage, etc. causes an error related to credentials, region or appid that is only resolved by using aws-amplify (the full library). Any update on this? I'm using Nextjs 12. |
Hello everyone, we are investigating this issue further on our end. We will provide feedback once we have some next steps. |
Same issue Ive encountered on my nextjs project using |
This is a pretty annoying problem. None of the proposed solutions worked for us (we are on Next 12.2). Any updates will be highly appreciated. |
Hello everyone, we have a tagged release that we are testing out that has bundle size reductions which also include removing the crypto libraries for NextJS apps. Could you try this tagged release and inform us if it reduces the bundle size for you - and what that reduction number look like to you? In order to use this version, you can run the following command in your terminal: Reducing the bundle size is one of our highest priority - and your feedback would be so helpful to help us drive enhancements in that area! |
@shubhamsharma98 - is this after doing a production build? Or were you still debugging this? The size here is definitely much larger than we expect it to be. |
Still in debugging, I'm a bit away from running the app in production but the numbers don't look very promising to go into production as-is. Any tips? |
Tip is to run a production build and then look at the numbers 😂 You can run the production build today. You don't need to wait for the app to go live. In Next it would be: |
@elie222 thanks for the tip. I'm new to this so perhaps that's why it was amusing to you but I'll do that and revert with my findings. |
Are you planning to introduce the optimization version also for amplify v5? |
@dr-star - the optimization was released with V5! You can try it now. |
|
Hello everybody, our team has been focusing on reducing the bundle size of the Amplify library, and starting v 5.2.5, we have been able to reduce the bundle size for the below use cases:
This is only the first step in our bundle size reduction efforts. In our next major version of Amplify JavaScript, we are going to provide better mechanisms for tree-shaking that will substantially reduce the bundle size. Stay tuned - we will provide updates on this issue when we have expected timelines mapped out. Please try out the newest version of Amplify, and let us know if you are seeing the improvements I've mentioned! Your feedback is essential to helping us improve our library! |
To be fair here: adding Amplify, Auth and Storage balloons the dev chunks by 5 MB. Even if that doesn't have impact on users it does have impact on DX and burns dev time. |
Hello @GriffinSauce - as part of our next major version, we are planning to substantially reduce the installation and bundle size for Amplify, both client and server side if you are building with NextJS. You can learn more about our areas of focus here. You can also provide us with feedback here if there are other things you are interested in seeing from Amplify JavaScript! #11833 |
With the release of the latest major version of Amplify (aws-amplify@>6), this issue should now be resolved! Please refer to our release announcement, migration guide, and documentation for more information. |
Describe the bug
I want to use Amplify Auth with my Next.js project. After I added aws-amplify to my project and imported 'Auth' to my index page the First load size increased from 64.1 kB to 308 kB without adding anything else. I also tried to analyze the problem with the webpack-bundle-analyzer and noticed that a lot of crypto libraries got loaded and some of them like bn.js multiple times (see screenshot below).
To Reproduce
import {Auth} from 'aws-amplify';
in your index.js pageExpected behavior
That the use of the aws-amplify Auth module will add way less than 240 kB to the first load size. Or is this an expected increase of size?
Code Snippet
package.json:
index.js
Screenshots
Screenshot from the webpack bundle analyzer:
Page size without amplify:
Page size with amplify:
What is Configured?
Amplify version: 3.3.14
Next.js version: 10.0.5
The text was updated successfully, but these errors were encountered: