Skip to content

Next.JS 14.2.23 - Importing @aws-sdk/crc64-nvme-crt" as required but fails to fetch S3 objects. #6822

Closed
@arealesramirez

Description

@arealesramirez

Checkboxes for prior research

Describe the bug

I have a project in Next.JS 14.2.23 facing the following error using NodeJS v20.10.0

Error: Please check whether you have installed the "@aws-sdk/crc64-nvme-crt" package explicitly. 
You must also register the package by calling [require("@aws-sdk/crc64-nvme-crt");] or an ESM equivalent such as [import "@aws-sdk/crc64-nvme-crt";]. 
For more information please go to https://github.com/aws/aws-sdk-js-v3#functionality-requiring-aws-common-runtime-crt
    at selectChecksumAlgorithmFunction (/Users/andres/Repos/my-project/node_modules/@aws-sdk/middleware-flexible-checksums/dist-cjs/index.js:209:15)
    at validateChecksumFromResponse (/Users/andres/Repos/my-project/node_modules/@aws-sdk/middleware-flexible-checksums/dist-cjs/index.js:411:35)
    at /Users/andres/Repos/my-project/node_modules/@aws-sdk/middleware-flexible-checksums/dist-cjs/index.js:466:11
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /Users/andres/Repos/my-project/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js:174:20
    at async /Users/andres/Repos/my-project/node_modules/@smithy/middleware-serde/dist-cjs/index.js:33:24
    at async /Users/andres/Repos/my-project/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js:483:18
    at async /Users/andres/Repos/my-project/node_modules/@smithy/middleware-retry/dist-cjs/index.js:321:38
    at async /Users/andres/Repos/my-project/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js:109:22
    at async /Users/andres/Repos/my-project/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js:136:14
    at async /Users/andres/Repos/my-project/node_modules/@aws-sdk/middleware-logger/dist-cjs/index.js:33:22
    at async getFileStreamFromS3 (webpack-internal:///(rsc)/./services/s3Service.ts:57:22)
    at async GET (webpack-internal:///(rsc)/./app/api/submissions/[submissionId]/file/route.ts:34:28)
    at async /Users/andres/Repos/my-project/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:57228
    at async eT.execute (/Users/andres/Repos/my-project/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:46851)
    at async eT.handle (/Users/andres/Repos/my-project/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:58760)
    at async doRender (/Users/andres/Repos/my-project/node_modules/next/dist/server/base-server.js:1366:42)
    at async cacheEntry.responseCache.get.routeKind (/Users/andres/Repos/my-project/node_modules/next/dist/server/base-server.js:1576:40)
    at async DevServer.renderToResponseWithComponentsImpl (/Users/andres/Repos/my-project/node_modules/next/dist/server/base-server.js:1496:28)
    at async DevServer.renderPageComponent (/Users/andres/Repos/my-project/node_modules/next/dist/server/base-server.js:1924:24)
    at async DevServer.renderToResponseImpl (/Users/andres/Repos/my-project/node_modules/next/dist/server/base-server.js:1962:32)
    at async DevServer.pipeImpl (/Users/andres/Repos/my-project/node_modules/next/dist/server/base-server.js:922:25)
    at async NextNodeServer.handleCatchallRenderRequest (/Users/andres/Repos/my-project/node_modules/next/dist/server/next-server.js:272:17)
    at async DevServer.handleRequestImpl (/Users/andres/Repos/my-project/node_modules/next/dist/server/base-server.js:818:17)
    at async /Users/andres/Repos/my-project/node_modules/next/dist/server/dev/next-dev-server.js:339:20
    at async Span.traceAsyncFn (/Users/andres/Repos/my-project/node_modules/next/dist/trace/trace.js:154:20)
    at async DevServer.handleRequest (/Users/andres/Repos/my-project/node_modules/next/dist/server/dev/next-dev-server.js:336:24)
    at async invokeRender (/Users/andres/Repos/my-project/node_modules/next/dist/server/lib/router-server.js:173:21)
    at async handleRequest (/Users/andres/Repos/my-project/node_modules/next/dist/server/lib/router-server.js:350:24)
    at async requestHandlerImpl (/Users/andres/Repos/my-project/node_modules/next/dist/server/lib/router-server.js:374:13)
    at async Server.requestListener (/Users/andres/Repos/my-project/node_modules/next/dist/server/lib/start-server.js:141:13) {
  '$metadata': { attempts: 1, totalRetryDelay: 0 }
}

This error occurs when I trigger the getFileStreamFromS3 function, which is a straightforward function that fetches an object from s3

import {
  GetObjectCommand,
  PutObjectCommand,
  PutObjectCommandOutput,
  S3Client,
} from "@aws-sdk/client-s3";
import "@ungap/with-resolvers";
import { pdf } from "@/utils/pdf-to-img";
const s3Client = new S3Client({
  region: process.env.AWS_REGION,
  credentials: {
    accessKeyId: process.env.AWS_ACCESS_KEY_ID,
    secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
  },
});


export const getFileStreamFromS3 = async (
  key: string
): Promise<ReadableStream> => {
  // await import("@aws-sdk/crc64-nvme-crt");

  const command = new GetObjectCommand({
    Bucket: process.env.AWS_S3_BUCKET_NAME!,
    Key: key,
    ChecksumMode: "ENABLED",
  });

  const response = await s3Client.send(command);

  if (!response.Body) {
    throw new Error("No body returned from S3");
  }

  return response.Body as ReadableStream;
};

// + other functions

According to the error message, I need to install and import @aws-sdk/crc64-nvme-crt, which I did

import "@aws-sdk/crc64-nvme-crt";

However, the error keeps showing up.

Here are the package versions I'm using:

        "@aws-sdk/client-s3": "^3.705.0",
        "@aws-sdk/crc64-nvme-crt": "^3.730.0",

Regression Issue

  • Select this option if this issue appears to be a regression.

SDK version number

@aws-sdk/[email protected], @aws-sdk/crc64-nvme-crt": "^3.730.0

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

v20.10.0

Reproduction Steps

Trigger the following function

export const getFileStreamFromS3 = async (
  key: string
): Promise<ReadableStream> => {
  // await import("@aws-sdk/crc64-nvme-crt");

  const command = new GetObjectCommand({
    Bucket: process.env.AWS_S3_BUCKET_NAME!,
    Key: key,
    ChecksumMode: "ENABLED",
  });

  const response = await s3Client.send(command);

  if (!response.Body) {
    throw new Error("No body returned from S3");
  }

  return response.Body as ReadableStream;
};

And it fails after triggering

  const response = await s3Client.send(command);

Observed Behavior

Here is the error thrown

Error: Please check whether you have installed the "@aws-sdk/crc64-nvme-crt" package explicitly. 
You must also register the package by calling [require("@aws-sdk/crc64-nvme-crt");] or an ESM equivalent such as [import "@aws-sdk/crc64-nvme-crt";]. 
For more information please go to https://github.com/aws/aws-sdk-js-v3#functionality-requiring-aws-common-runtime-crt
    at selectChecksumAlgorithmFunction (/Users/andres/Repos/my-project/node_modules/@aws-sdk/middleware-flexible-checksums/dist-cjs/index.js:209:15)
    at validateChecksumFromResponse (/Users/andres/Repos/my-project/node_modules/@aws-sdk/middleware-flexible-checksums/dist-cjs/index.js:411:35)
    at /Users/andres/Repos/my-project/node_modules/@aws-sdk/middleware-flexible-checksums/dist-cjs/index.js:466:11
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /Users/andres/Repos/my-project/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js:174:20
    at async /Users/andres/Repos/my-project/node_modules/@smithy/middleware-serde/dist-cjs/index.js:33:24
    at async /Users/andres/Repos/my-project/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js:483:18
    at async /Users/andres/Repos/my-project/node_modules/@smithy/middleware-retry/dist-cjs/index.js:321:38
    at async /Users/andres/Repos/my-project/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js:109:22
    at async /Users/andres/Repos/my-project/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js:136:14
    at async /Users/andres/Repos/my-project/node_modules/@aws-sdk/middleware-logger/dist-cjs/index.js:33:22
    at async getFileStreamFromS3 (webpack-internal:///(rsc)/./services/s3Service.ts:57:22)
    at async GET (webpack-internal:///(rsc)/./app/api/submissions/[submissionId]/file/route.ts:34:28)
    at async /Users/andres/Repos/my-project/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:57228
    at async eT.execute (/Users/andres/Repos/my-project/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:46851)
    at async eT.handle (/Users/andres/Repos/my-project/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:58760)
    at async doRender (/Users/andres/Repos/my-project/node_modules/next/dist/server/base-server.js:1366:42)
    at async cacheEntry.responseCache.get.routeKind (/Users/andres/Repos/my-project/node_modules/next/dist/server/base-server.js:1576:40)
    at async DevServer.renderToResponseWithComponentsImpl (/Users/andres/Repos/my-project/node_modules/next/dist/server/base-server.js:1496:28)
    at async DevServer.renderPageComponent (/Users/andres/Repos/my-project/node_modules/next/dist/server/base-server.js:1924:24)
    at async DevServer.renderToResponseImpl (/Users/andres/Repos/my-project/node_modules/next/dist/server/base-server.js:1962:32)
    at async DevServer.pipeImpl (/Users/andres/Repos/my-project/node_modules/next/dist/server/base-server.js:922:25)
    at async NextNodeServer.handleCatchallRenderRequest (/Users/andres/Repos/my-project/node_modules/next/dist/server/next-server.js:272:17)
    at async DevServer.handleRequestImpl (/Users/andres/Repos/my-project/node_modules/next/dist/server/base-server.js:818:17)
    at async /Users/andres/Repos/my-project/node_modules/next/dist/server/dev/next-dev-server.js:339:20
    at async Span.traceAsyncFn (/Users/andres/Repos/my-project/node_modules/next/dist/trace/trace.js:154:20)
    at async DevServer.handleRequest (/Users/andres/Repos/my-project/node_modules/next/dist/server/dev/next-dev-server.js:336:24)
    at async invokeRender (/Users/andres/Repos/my-project/node_modules/next/dist/server/lib/router-server.js:173:21)
    at async handleRequest (/Users/andres/Repos/my-project/node_modules/next/dist/server/lib/router-server.js:350:24)
    at async requestHandlerImpl (/Users/andres/Repos/my-project/node_modules/next/dist/server/lib/router-server.js:374:13)
    at async Server.requestListener (/Users/andres/Repos/my-project/node_modules/next/dist/server/lib/start-server.js:141:13) {
  '$metadata': { attempts: 1, totalRetryDelay: 0 }
}

Expected Behavior

I expected to fetch the file/object from S3

Possible Solution

No response

Additional Information/Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.p1This is a high priority issuequeuedThis issues is on the AWS team's backlog

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions