Skip to content
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

Nextjs build error for aws sdk client s3 / request presigner... on versions higher than 3.623.0 #6411

Open
3 tasks done
luong-komorebi opened this issue Aug 27, 2024 · 10 comments
Assignees
Labels
bug This issue is a bug. p2 This is a standard priority issue

Comments

@luong-komorebi
Copy link

Checkboxes for prior research

Describe the bug

When building nextjs with

    "@aws-sdk/client-s3": "3.629.0",
    "@aws-sdk/s3-request-presigner": "3.629.0"

or any higher versions than 3.623.0

we were reported these errors

web-app:build: ../node_modules/.pnpm/@aws-sdk [email protected]/node_modules/@aws-sdk/middleware-sdk-s3/dist-es/s3-express/functions/s3ExpressHttpSigningMiddleware.js   43 modules
web-app:build: Cannot get final name for export 'NO_RETRY_INCREMENT' of ../node_modules/.pnpm/@smithy [email protected]/node_modules/@smithy/util-retry/dist-es/index.js

while the same log has been reported a few times on the internet with some possible resolution, like this one from stackoverflow or inside this issue on Github , I find it strange that I never had to apply any of these configs or hacks or fixes prior to version 3.623.0 to make next build work

I am not too familiar with @smithy/util-retry as well as the changes in changelog is not super relevant to this error, so I dont know what is going on. But by bruteforcing versions, I find that it starts happening at 3.624.0 and the last version I was to install without errors is 3.623.0

Please help me understand why this error is happening. The latest version (3.637.0) has not fixed this yet

SDK version number

@aws-sdk/[email protected], @aws-sdk/[email protected]

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

v20.13.1

Reproduction Steps

Install @aws-sdk/client-s3@^3.624.0 in any nextjs project and start next build it

Observed Behavior

web-app:build: > [email protected] build /app/web-app
web-app:build: > next build
web-app:build:
web-app:build:   ▲ Next.js 14.2.5
web-app:build:   - Environments: .env
web-app:build:   - Experiments (use with caution):
web-app:build:     · staleTimes
web-app:build:     · instrumentationHook
web-app:build:     · outputFileTracingRoot
web-app:build:
web-app:build:    Creating an optimized production build ...
<... other irrelevant logs are stripped ...>
web-app:build: Failed to compile.
web-app:build:
web-app:build: ../node_modules/.pnpm/@aws-sdk [email protected]/node_modules/@aws-sdk/middleware-sdk-s3/dist-es/s3-express/functions/s3ExpressHttpSigningMiddleware.js   43 modules
web-app:build: Cannot get final name for export 'NO_RETRY_INCREMENT' of ../node_modules/.pnpm/@smithy [email protected]/node_modules/@smithy/util-retry/dist-es/index.js

Expected Behavior

No errors on building

Possible Solution

Revert to 3.623.0

Additional Information/Context

smithy-codegen

@luong-komorebi luong-komorebi added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 27, 2024
@luong-komorebi luong-komorebi changed the title Nextjs build error for aws sdk client s3 / request presigner... on versions higher than 3.620.1 Nextjs build error for aws sdk client s3 / request presigner... on versions higher than 3.623.0 Aug 27, 2024
@aBurmeseDev
Copy link
Member

Hi @luong-komorebi - thanks for reporting.

While we further look into it, can you share your SDK minimal repro code with Next.js? Here's my quick repro attempt with 3.629.0 and it works as expected:

npx create-next-app next-aws-sdk-repro
cd next-aws-sdk-repro
npm install @aws-sdk/[email protected] @aws-sdk/[email protected]

SDK

import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";

const s3Client = new S3Client({
  region: "us-west-1",
  credentials: {
    accessKeyId: "ACCESS_KEY_ID",
    secretAccessKey: "SECRET_ACCESS_KEY",
  },
});

export default async function handler(req, res) {
  try {
    const command = new GetObjectCommand({
      Bucket: "BUCKET_NAME",
      Key: "OBJECT_KEY",
    });

    const signedUrl = await getSignedUrl(s3Client, command, {
      expiresIn: 3600,
    });

    res.status(200).json({ signedUrl });
  } catch (error) {
    console.error(error);
    res.status(500).json({ error: error.message });
  }
}

Best,
John

@aBurmeseDev aBurmeseDev self-assigned this Aug 28, 2024
@aBurmeseDev aBurmeseDev added response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Aug 28, 2024
@luong-komorebi
Copy link
Author

@aBurmeseDev sorry I could not share the original source code and I could not also reproduce this in a fresh nextjs project with some similar next.config.js setting so I am not sure what was causing the error

Please feel free to close this issue.
Meanwhile I fix things on my side by adding

serverComponentsExternalPackages: [
  "@aws-sdk/client-s3",
  "@aws-sdk/s3-request-presigner"
]

like some suggestions on the internet and it works.
It is weird that I did not have to do this on earlier versions of aws-sdk/client-s3
as well as nextjs has already pre-configured this on their side https://github.com/vercel/next.js/blob/0bf7f52db8b2c1e0b13d332de105fab645240e1e/packages/next/src/lib/server-external-packages.json#L2

@kasperaamodt
Copy link

kasperaamodt commented Sep 2, 2024

I'm experiencing the same issue right now. Same problem on .629 and latest .637

@oliver-lister
Copy link

Same issue for me, reverting to 3.623.0 worked as a temporary fix.

@magoz
Copy link

magoz commented Sep 2, 2024

Add this to your nextjs config:

// Nextjs 14
const nextConfig = {
  experimental: {
    serverComponentsExternalPackages: ['@aws-sdk/client-s3', '@aws-sdk/s3-request-presigner']
  }

Notice that serverComponentsExternalPackages will become stable in next.js 15 and will be renamed to serverExternalPackages.

// Nextjs 15
const nextConfig = {
  serverExternalPackages: ['@aws-sdk/client-s3', '@aws-sdk/s3-request-presigner'],
}

Links to the docs:
https://nextjs.org/docs/app/api-reference/next-config-js/serverExternalPackages

@kasperaamodt
Copy link

kasperaamodt commented Sep 2, 2024

@magoz I already have that in my config, and it did not fix anything. Reverting to .623 worked.

@magoz
Copy link

magoz commented Sep 2, 2024

@kasperaamodt, double-check that you add the serverComponentsExternalPackages within the experimental object. It wasn't working for me either until I realized.

In any case, I agree that this must be fixed.

@kasperaamodt
Copy link

@magoz Ahh, sorry i did not catch that! My bad. That fixed it.

@luong-komorebi
Copy link
Author

Ideally, we should not have to config the serverComponentsExternalPackages or serverExternalPackages manually,
because since this commit vercel/next.js@a06775c, next has already excluded aws client s3 and s3-request-presigner by default. I am still unable to figure out why this happens

@arthberman
Copy link

same here with '@aws-sdk/middleware-sdk-s3', '@aws-sdk/client-s3', '@aws-sdk/s3-request-presigner' packages

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. label Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

6 participants