amplify-js: Module not found: Can't resolve 'aws-crt' when using API in nextjs@13.2
Before opening, please confirm:
- I have searched for duplicate or closed issues and discussions.
- I have read the guide for submitting bug reports.
- I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
JavaScript Framework
Next.js
Amplify APIs
GraphQL API
Amplify Categories
api
Environment information
# Put output below this line
System:
OS: macOS 11.6
CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
Memory: 164.22 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 18.14.0 - ~/.nvm/versions/node/v18.14.0/bin/node
Yarn: 1.22.17 - /usr/local/bin/yarn
npm: 9.3.1 - ~/.nvm/versions/node/v18.14.0/bin/npm
Browsers:
Chrome: 110.0.5481.100
Firefox: 95.0
Safari: 15.0
npmGlobalPackages:
@aws-amplify/cli: 10.7.3
corepack: 0.15.3
npm: 9.3.1
Describe the bug
I have a NEXTjs@13.2 app with the new app directory enabled.
I also have installed “aws-amplify”: “^5.0.16”
Now it’s enough that I import and console log API module to get bunch of errors in the console:
"use client" // it doesn't matter if you have this directive...
import { API } from "aws-amplify";
console.log(API);
errors:
wait - compiling...
warn - ./node_modules/@aws-sdk/client-lex-runtime-service/node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
Module not found: Can't resolve 'aws-crt' in '/Users/tomekm/Desktop/tixy-frontend/node_modules/@aws-sdk/client-lex-runtime-service/node_modules/@aws-sdk/util-user-agent-node/dist-cjs'
Import trace for requested module:
./node_modules/@aws-sdk/client-lex-runtime-service/node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
./node_modules/@aws-sdk/client-lex-runtime-service/node_modules/@aws-sdk/util-user-agent-node/dist-cjs/index.js
./node_modules/@aws-sdk/client-lex-runtime-service/dist-cjs/runtimeConfig.js
./node_modules/@aws-sdk/client-lex-runtime-service/dist-cjs/LexRuntimeServiceClient.js
./node_modules/@aws-sdk/client-lex-runtime-service/dist-cjs/index.js
./node_modules/@aws-amplify/interactions/lib/Providers/AWSLexProvider.js
./node_modules/@aws-amplify/interactions/lib/index.js
./node_modules/aws-amplify/lib/index.js
./src/app/[locale]/dashboard/create-event/CreateEventForm/CreateEventForm.tsx
./src/app/[locale]/dashboard/create-event/page.tsx
./node_modules/@aws-sdk/client-lex-runtime-v2/node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
Module not found: Can't resolve 'aws-crt' in '/Users/tomekm/Desktop/tixy-frontend/node_modules/@aws-sdk/client-lex-runtime-v2/node_modules/@aws-sdk/util-user-agent-node/dist-cjs'
Import trace for requested module:
./node_modules/@aws-sdk/client-lex-runtime-v2/node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
./node_modules/@aws-sdk/client-lex-runtime-v2/node_modules/@aws-sdk/util-user-agent-node/dist-cjs/index.js
./node_modules/@aws-sdk/client-lex-runtime-v2/dist-cjs/runtimeConfig.js
./node_modules/@aws-sdk/client-lex-runtime-v2/dist-cjs/LexRuntimeV2Client.js
./node_modules/@aws-sdk/client-lex-runtime-v2/dist-cjs/index.js
./node_modules/@aws-amplify/interactions/lib/Providers/AWSLexV2Provider.js
./node_modules/@aws-amplify/interactions/lib/index.js
./node_modules/aws-amplify/lib/index.js
./src/app/[locale]/dashboard/create-event/CreateEventForm/CreateEventForm.tsx
./src/app/[locale]/dashboard/create-event/page.tsx
./node_modules/@aws-sdk/client-location/node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
Module not found: Can't resolve 'aws-crt' in '/Users/tomekm/Desktop/tixy-frontend/node_modules/@aws-sdk/client-location/node_modules/@aws-sdk/util-user-agent-node/dist-cjs'
Import trace for requested module:
./node_modules/@aws-sdk/client-location/node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
./node_modules/@aws-sdk/client-location/node_modules/@aws-sdk/util-user-agent-node/dist-cjs/index.js
./node_modules/@aws-sdk/client-location/dist-cjs/runtimeConfig.js
./node_modules/@aws-sdk/client-location/dist-cjs/LocationClient.js
./node_modules/@aws-sdk/client-location/dist-cjs/index.js
./node_modules/@aws-amplify/geo/lib/Providers/AmazonLocationServiceProvider.js
./node_modules/@aws-amplify/geo/lib/Geo.js
./node_modules/@aws-amplify/geo/lib/index.js
./node_modules/aws-amplify/lib/index.js
./src/app/[locale]/dashboard/create-event/CreateEventForm/CreateEventForm.tsx
./src/app/[locale]/dashboard/create-event/page.tsx
./node_modules/@aws-sdk/client-pinpoint/node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
Module not found: Can't resolve 'aws-crt' in '/Users/tomekm/Desktop/tixy-frontend/node_modules/@aws-sdk/client-pinpoint/node_modules/@aws-sdk/util-user-agent-node/dist-cjs'
Import trace for requested module:
./node_modules/@aws-sdk/client-pinpoint/node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
./node_modules/@aws-sdk/client-pinpoint/node_modules/@aws-sdk/util-user-agent-node/dist-cjs/index.js
./node_modules/@aws-sdk/client-pinpoint/dist-cjs/runtimeConfig.js
./node_modules/@aws-sdk/client-pinpoint/dist-cjs/PinpointClient.js
./node_modules/@aws-sdk/client-pinpoint/dist-cjs/index.js
./node_modules/@aws-amplify/notifications/lib/InAppMessaging/Providers/AWSPinpointProvider/index.js
./node_modules/@aws-amplify/notifications/lib/InAppMessaging/Providers/index.js
./node_modules/@aws-amplify/notifications/lib/InAppMessaging/index.js
./node_modules/@aws-amplify/notifications/lib/index.js
./node_modules/aws-amplify/lib/index.js
./src/app/[locale]/dashboard/create-event/CreateEventForm/CreateEventForm.tsx
./src/app/[locale]/dashboard/create-event/page.tsx
./node_modules/@aws-sdk/client-sso/node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
Module not found: Can't resolve 'aws-crt' in '/Users/tomekm/Desktop/tixy-frontend/node_modules/@aws-sdk/client-sso/node_modules/@aws-sdk/util-user-agent-node/dist-cjs'
Import trace for requested module:
./node_modules/@aws-sdk/client-sso/node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
./node_modules/@aws-sdk/client-sso/node_modules/@aws-sdk/util-user-agent-node/dist-cjs/index.js
./node_modules/@aws-sdk/client-sso/dist-cjs/runtimeConfig.js
./node_modules/@aws-sdk/client-sso/dist-cjs/SSOClient.js
./node_modules/@aws-sdk/client-sso/dist-cjs/index.js
./node_modules/@aws-sdk/credential-provider-sso/dist-cjs/resolveSSOCredentials.js
./node_modules/@aws-sdk/credential-provider-sso/dist-cjs/fromSSO.js
./node_modules/@aws-sdk/credential-provider-sso/dist-cjs/index.js
./node_modules/@aws-sdk/client-lex-runtime-service/node_modules/@aws-sdk/credential-provider-node/dist-cjs/defaultProvider.js
./node_modules/@aws-sdk/client-lex-runtime-service/node_modules/@aws-sdk/credential-provider-node/dist-cjs/index.js
./node_modules/@aws-sdk/client-lex-runtime-service/dist-cjs/runtimeConfig.js
./node_modules/@aws-sdk/client-lex-runtime-service/dist-cjs/LexRuntimeServiceClient.js
./node_modules/@aws-sdk/client-lex-runtime-service/dist-cjs/index.js
./node_modules/@aws-amplify/interactions/lib/Providers/AWSLexProvider.js
./node_modules/@aws-amplify/interactions/lib/index.js
./node_modules/aws-amplify/lib/index.js
./src/app/[locale]/dashboard/create-event/CreateEventForm/CreateEventForm.tsx
./src/app/[locale]/dashboard/create-event/page.tsx
./node_modules/@aws-sdk/client-sts/node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
Module not found: Can't resolve 'aws-crt' in '/Users/tomekm/Desktop/tixy-frontend/node_modules/@aws-sdk/client-sts/node_modules/@aws-sdk/util-user-agent-node/dist-cjs'
Import trace for requested module:
./node_modules/@aws-sdk/client-sts/node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
./node_modules/@aws-sdk/client-sts/node_modules/@aws-sdk/util-user-agent-node/dist-cjs/index.js
./node_modules/@aws-sdk/client-sts/dist-cjs/runtimeConfig.js
./node_modules/@aws-sdk/client-sts/dist-cjs/STSClient.js
./node_modules/@aws-sdk/client-sts/dist-cjs/index.js
./node_modules/@aws-sdk/client-lex-runtime-service/dist-cjs/runtimeConfig.js
./node_modules/@aws-sdk/client-lex-runtime-service/dist-cjs/LexRuntimeServiceClient.js
./node_modules/@aws-sdk/client-lex-runtime-service/dist-cjs/index.js
./node_modules/@aws-amplify/interactions/lib/Providers/AWSLexProvider.js
./node_modules/@aws-amplify/interactions/lib/index.js
./node_modules/aws-amplify/lib/index.js
./src/app/[locale]/dashboard/create-event/CreateEventForm/CreateEventForm.tsx
./src/app/[locale]/dashboard/create-event/page.tsx
./node_modules/node-fetch/lib/index.js
Module not found: Can't resolve 'encoding' in '/Users/tomekm/Desktop/tixy-frontend/node_modules/node-fetch/lib'
Import trace for requested module:
./node_modules/node-fetch/lib/index.js
./node_modules/isomorphic-unfetch/index.js
./node_modules/amazon-cognito-identity-js/lib/Client.js
./node_modules/amazon-cognito-identity-js/lib/CognitoUserPool.js
./node_modules/amazon-cognito-identity-js/lib/index.js
./node_modules/@aws-amplify/auth/lib/index.js
./node_modules/aws-amplify/lib/index.js
./src/app/[locale]/dashboard/create-event/CreateEventForm/CreateEventForm.tsx
./src/app/[locale]/dashboard/create-event/page.tsx
Also compiling takes more time - extra couple of seconds - for some reason.
Expected behavior
There are no errors in the console and importing library doesn’t affect bundling time.
Reproduction steps
- Create new nextjs@13 project
yarn create next-app amplify-test - Use experimental app directory:

- Install aws-amplify@5.16.02
- go to src/app/page.js and paste this code:
import { API } from "aws-amplify";
console.log(API)
Now notice bundling takes more time and you get bunch of errors printed in the console.
Code Snippet
// Put your code below this line.
Log output
// Put your logs below this line
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 26
- Comments: 53 (10 by maintainers)
Commits related to this issue
- Ignore aws-crt warning References: - https://github.com/aws-amplify/amplify-js/issues/11030#issuecomment-1598207365 — committed to frostehhh/google-keep-clone by frostehhh a year ago
- Ignore aws-crt warning References: - https://github.com/aws-amplify/amplify-js/issues/11030#issuecomment-1598207365 — committed to frostehhh/google-keep-clone by frostehhh a year ago
For those who’s using Next.js, adding the following to your
next.config.jswill get rid of the warning:The issue is caused by Next.js/Webpack warning on require being called with an expression, which is valid in Node.js environment.
Hello Josh, we apologize for the delay in resolving this issue. Based on our investigations, making the necessary enhancement requires breaking changes. We are currently working on introducing an improved experience for App Router as part of our next major version.
Hello everyone, we have validated this and this error is coming from the AWS SDK clients we are using. Although this does not affect the functionality of your app, the warning is confusing. We will address this warning in a future release.
I have same error with nextjs app dir (13.4.0-stable) + aws-amplify (5.2.0) I tried the webpack config solution but still the same…
@Tomekmularczyk @lukedanielson I must’ve missed that warning but I do see it. I only seem to get these warnings when I use Next 13’s experimental
appdirectory for routing. However, these warnings don’t seem to keep my pages from rendering.If I refactor to use the
pagesdirectory the warnings go away.Since this is consistently reproducible, I’ve marked this as a bug for the team to investigate further in case something needs to be addressed on our end before the library can be fully compatible with Next 13’s experimental features once they are stable.
Hi, I just tried installing both and I have less warnings but there are some still:
Any updates on this?
These steps resolved the warning for me:
Note. Stop the dev server it’s already running Note 2. The steps below assumes you are using
yarnbut they should also work fornpmUsing: Next 13.4+ Apple M1 Pro Mac
.nextfolderyarn add aws-crt encoding -Dyarn devAll warning dissapeared in my case.
Yeah, this one is hurting lots of folks that have adopted the new router. It’s been months and the various webpack/dependency solutions aren’t working. We’ve desperately had to move to faking our AppSync responses (which Amplify would otherwise handle for us). Our Next app (13.4.1) is taking 10+s to load and I couldn’t get any of the above solutions to silence the errors.
Any update on this? This issue has not been resolved for months.
This is causing Nextjs apps with the app directory to have a 5-7+ seconds initial delay when rendering the page… this causes some horrible user experience.
How can there be official docs on how to integrate Amplify with new Nextjs app directory while issues like this exists.
https://github.com/aws-amplify/amplify-js/issues/11030#issuecomment-1598207365 works for me. Thanks @phuctm97 ! Currently i have similar issue but using S3-client (the package shown on the error is “@aws-sdk/signature-v4-crt” on this case). So i added to the regexp:
The solution from https://github.com/aws-amplify/amplify-js/issues/11030#issuecomment-1598207365 works perfectly thanks @phuctm97 but just adding my new one below because it doesn’t really the webpack anymore since next 13.14.9 I’m on 13.14.12 currently.
It is functioning as expected, but the warning is impacting the fast refresh in Next.js 13 app router. Is there any way to resolve this issue?
Hi, I’m not using Turbopack, I’m running the project with
next devso it should be using webpack. The only tweak I did to standard nextjs configuration is that I use the newappdirectory. When do you think it might be fixed?I used
webpack: (config, { webpack, isServer, nextRuntime }) => {and cold start for page went to 7s. Above solution works better IMOHi @weisisheng - the warnings should not be affecting the functionality of your app, we had been able to validate that in our testing. We do not have a timeline yet for addressing the warnings, but we have a path forward now which includes cleaning up our underlying dependencies to remove this warning from showing up. Did you try following our guidance here on using the app directory? https://docs.amplify.aws/lib/ssr/q/platform/js/#use-amplify-with-nextjs-app-router-app-directory
Here is a very basic repo reproducing the problem: https://github.com/Tomekmularczyk/amplify-next and here is the recording:
https://github.com/aws-amplify/amplify-js/assets/12544704/6807fc40-4f9a-4515-83c0-3d8faf2a07c7
{URL}/enNote that:
appdirectoryimport "./amplifyConfigureClient"; import "./amplifyConfigureServer";problem does not happenIt doesn’t matter if it is AWS or Vercel hosting - delay happens in both.
I was investigating why our app is taking 8 seconds to load a page on production environment deployed to Vercel. After lot of investigation it turned out that if remove amplify configs as explained here the page loads in 3 seconds. It happens right after deployment on initial load or after an hour of iddle time.
My hunch is that it is related to the issue described here. In such case this REALLY hurts not only local dev performance but production as well 😕
Just a quick update here, looks like the issue has to be fixed on our end for Turbopack projects in general.
Here’s the issue to track that we’ve opened with the aws sdk team: https://github.com/aws/aws-sdk-js-v3/issues/4126
Closing this issue as we have not had a response on previous comments tied to webpack. If anyone is still experiencing this, please feel free to reply back and provide any information previously requested and we’d be happy to re-open the issue.
Thank you!
this is only removing the warning, but the loading issue is still there
I’m having the same issue as @bear-bibeault.
"next": "^13.4.9", "typescript": "5.1.3",next.config.js
attempted to convert to .mjs and added “type”: “module” to package.json did not solve the issue.
Same issues with fresh aws-amplify install on next 13. no turbopack
Here’s a potential solution: Make sure that
aws-amplify(or any other package that’s the source of the problem) is included in thepackage.jsonof your Next.js project (not in a dependent package). I had a similar problem withmongodband I hadmongodbadded in separate package in my monorepo. I copiedmongodbdependency to the Next.js project and the issue was gone.I’m getting this same issue, using APP directory, no Turbopack, Next version: 13.2.4
Excellent! Thank you for the quick response!
I was using SQS not amplify but still had the same error and I was able to solve it in nextjs 13.4 by adding “use server” on top of the file where the error came from. Maybe helps someone
Is there any estimated timeline on this issue? I am finding the warning makes next.js 13.4.x completely unusable on Amplify. The browser keeps trying to render, hangs and nothing results. I am hesitant to use the pages router choice as I found other issues with it. Thanks in advance.
^above is not true for me. I am also on NextJS
13.4.3/ Amplify5.2.2and I see the warning (usingappdirectory FWIW) .Hi guys ! I just deployed Nextj @13.4.3 version to aws amplify by connecting it with GitHub, it worked fine as expected. You can give a try to latest version
I had the
Critical dependency: the request of a dependency is an expressionwarning and this answer helped me to find a fix.I added
aws-crtas a main dependency and in my next.js webpack config :This removes the warning, I couldn’t really explain why.
Hi @Tomekmularczyk I ran into this issue recently as well. I was able to work around it by installing
aws-crtandencodingas dependencies. Does this work for you as a temporary workaround?@chrisbonifacio Next 14 + Amplify v6 also works for me with turbopack 💯
@Tomekmularczyk I don’t think this is an issue anymore in Next 14 + Amplify v6, at least in my experience recently. Have you been able to upgrade and confirm that’s the case for you as well?
Hi, for the sake of solution sharing, I just threw away the aws-amplify library and did my own “implementation” of the network calls to the Cognito Service with vanilla Javascript. I made it work previously, but the cold loading issue wasn’t acceptable so I reverse engineered the network calls of the library 😃 Everything is done through the same cognito endpoint, but you need to configure the custom http header ‘X-Amz-Target’. I persist the session through the cookies and an AuthProvider component.
Below an example of my
auth/index.tsfile, hope this helps.And this is for example the submitLoginHandler in the login form page:
Attached my files:
github-aws-cognito.zip
Issue: Can confirm my solution will cause ‘webpack not found’ because of this related issue: https://github.com/vercel/next.js/issues/52366
Update: The above issue was fixed in latest Next.js version.
Same issue 😦
Im using Next.js and the
"@aws-sdk/client-cloudfront": "^3.321.1", "@aws-sdk/client-s3": "^3.306.0",library’s and get a ton of warning messages. Everything does work so far so thats great at least. Is there anyway to try and suppress the messages until a fix is out?I have same error with nextjs app dir (13.4.1) + @aws-sdk/client-dynamodb
@chrisbonifacio Yes, I am experiencing the same thing: only warnings when using the experimental
appdirectory and it not preventing rendering. Sounds good, will check back in once the experimental features are stable.