aws / aws-sdk-js

AWS SDK for JavaScript in the browser and Node.js (In Maintenance Mode, End-of-Life on 09/08/2025). The AWS SDK for JavaScript v3 in the browser and Node.js is available here: https://github.com/aws/aws-sdk-js-v3
https://aws.amazon.com/developer/language/javascript/
Apache License 2.0
7.6k stars 1.55k forks source link

Node @aws-sdk/client-s3 throws an error at import: options.useFipsEndpoint ?? false (Invalid or unexpected token) #4658

Closed SamyGarib closed 4 months ago

SamyGarib commented 4 months ago

Describe the bug

I'm runing Node 20.14.0 and aws-sdk/client-s3 ^3.609.0

The error occurs just when I import the library: const { PutObjectCommand, S3Client } = require("@aws-sdk/client-s3"); /node_modules/@aws-sdk/client-s3/dist-cjs/index.js:282 useFipsEndpoint: options.useFipsEndpoint ?? false Invalid or unexpected token (it points to ??)

To double check I'm using the correct runtime I added this line to my script: console.log(Node.js version: ${process.version});

Expected Behavior

It shouldn't have thrown an error.

Current Behavior

node_modules/@aws-sdk/client-s3/dist-cjs/index.js:282 useFipsEndpoint: options.useFipsEndpoint ?? false, SyntaxError: Invalid or unexpected token at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)

Reproduction Steps

const { S3Client } = require("@aws-sdk/client-s3");

Possible Solution

No response

Additional Information/Context

No response

SDK version used

v3

Environment details (OS name and version, etc.)

Linux (ubuntu 24.04), 6.8.0-36-generic

SamyGarib commented 4 months ago

This issue happened because I was calling the script with esm flag, like "node -r esm download.js" I don't know If this should work either way, but I managed to make it work so I'm closing the tickets.