Closed loveheenavasu closed 3 months ago
Hi @loveheenavasu ,
Can you provide us with some more info? Contents of package json and your actual code? My assumptions is that you are trying to use ES6 imports but you didn't specify that in your budnler / config. This doesn't look like an SDK issue, but rather a config problem either with npm or with Electron.
Please check out this stackoverflow thread.
Thanks, Ran~
Hi @RanVaknin , I tried to replicate the error on a similar repo. I am providing the link here . You can reach out to the "/app/aws/index.js" file for reference. I just Imported the two packages(@aws-sdk/client-s3 and s3-sync-client).
[0] Module parse failed: Unexpected token (8:41)
[0] You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
[0] | this.maxAttemptsProvider = maxAttemptsProvider;
[0] | this.mode = RETRY_MODES.ADAPTIVE;
[0] > const { rateLimiter } = options ?? {};
[0] | this.rateLimiter = rateLimiter ?? new DefaultRateLimiter();
[0] | this.standardRetryStrategy = new StandardRetryStrategy(maxAttemptsProvider);
[0] @ ./node_modules/@aws-sdk/util-retry/dist-es/index.js 1:0-40 1:0-40
[0] @ ./node_modules/@aws-sdk/middleware-retry/dist-es/delayDecider.js
[0] @ ./node_modules/@aws-sdk/middleware-retry/dist-es/index.js
[0] @ ./node_modules/@aws-sdk/client-s3/dist-es/S3Client.js
[0] @ ./node_modules/@aws-sdk/client-s3/dist-es/index.js
[0] @ ./app/aws/index.js
[0] @ ./app/App.js
[0] @ ./app/main.js
[0] @ multi @babel/polyfill ./app/main.js
[0]
[0] ERROR in ./node_modules/@aws-sdk/middleware-user-agent/dist-es/user-agent-middleware.js 9:30
[0] Module parse failed: Unexpected token (9:30)
[0] You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
[0] | return next(args);
[0] | const { headers } = request;
[0] > const userAgent = context?.userAgent?.map(escapeUserAgent) || [];
[0] | const defaultUserAgent = (await options.defaultUserAgentProvider()).map(escapeUserAgent);
[0] | const customUserAgent = options?.customUserAgent?.map(escapeUserAgent) || [];
[0] @ ./node_modules/@aws-sdk/middleware-user-agent/dist-es/index.js 2:0-40 2:0-40
[0] @ ./node_modules/@aws-sdk/client-s3/dist-es/S3Client.js
[0] @ ./node_modules/@aws-sdk/client-s3/dist-es/index.js
[0] @ ./app/aws/index.js
[0] @ ./app/App.js
[0] @ ./app/main.js
[0] @ multi @babel/polyfill ./app/main.js
I am getting this error on multiple files.
Hi @loveheenavasu, this issue is indeed a transpiling issue. Basically, the errors you see there happens because due to that we use optional chaining, which is a feature introduced as part of ES2020, and probably older browsers will not support it. That is why we need to use a transpiler, which in this case I see you are using babel. I am still working on trying to adjust the configuration you have set in the test repo for reproducing, but still not able to make it work. However, by transpiling the @aws-sdk folder manually it made the errors to be gone. For example, I ran the following command from the root directory of the project:
npx babel node_modules/@aws-sdk --out-dir node_modules/@aws-sdk --presets=@babel/preset-env
And the command above did the trick. Nonetheless I will keep trying to find the best way around this and I will update this thread with new details.
Thanks!
I had a similar issue consuming this package from NextJS, which no longer uses Babel by default. I found the specific submodules that were causing me problems and added the following to my next.config.js
as per the docs:
/** @type {import('next').NextConfig} */
const nextConfig = {
// ...
transpilePackages: [
"@aws-sdk/fetch-http-handler",
"@aws-sdk/signature-v4",
],
};
module.exports = nextConfig;
@yenfryherrerafeliz any news?
also having an issue
npx babel node_modules/@aws-sdk --out-dir node_modules/@aws-sdk --presets=@babel/preset-env
npx serverless deploy --stage $stage --verbose
not working
I have some clues here, my project works fine with @aws-sdk/client-s3@3.171.0
, but not @aws-sdk/client-s3@3.414.0
.
Below are two versions of the lock file.
"@aws-sdk/client-s3@^3.121.0":
version "3.171.0"
resolved "https://registry.npmmirror.com/@aws-sdk/client-s3/-/client-s3-3.171.0.tgz#d77275ecc4d9e40cbd207e164bb9c18c836629e4"
integrity sha512-UFPnf9xG7H6Mku9tfVH7oSXq65oH0mb8vvfeUWsi+KKedvMdww7fVWmXtcgnsB9nmXLF2PfrQrdaz2uid4rpgQ==
dependencies:
"@aws-crypto/sha1-browser" "2.0.0"
"@aws-crypto/sha256-browser" "2.0.0"
"@aws-crypto/sha256-js" "2.0.0"
"@aws-sdk/client-sts" "3.171.0"
"@aws-sdk/config-resolver" "3.171.0"
"@aws-sdk/credential-provider-node" "3.171.0"
"@aws-sdk/eventstream-serde-browser" "3.171.0"
"@aws-sdk/eventstream-serde-config-resolver" "3.171.0"
"@aws-sdk/eventstream-serde-node" "3.171.0"
"@aws-sdk/fetch-http-handler" "3.171.0"
"@aws-sdk/hash-blob-browser" "3.171.0"
"@aws-sdk/hash-node" "3.171.0"
"@aws-sdk/hash-stream-node" "3.171.0"
"@aws-sdk/invalid-dependency" "3.171.0"
"@aws-sdk/md5-js" "3.171.0"
"@aws-sdk/middleware-bucket-endpoint" "3.171.0"
"@aws-sdk/middleware-content-length" "3.171.0"
"@aws-sdk/middleware-expect-continue" "3.171.0"
"@aws-sdk/middleware-flexible-checksums" "3.171.0"
"@aws-sdk/middleware-host-header" "3.171.0"
"@aws-sdk/middleware-location-constraint" "3.171.0"
"@aws-sdk/middleware-logger" "3.171.0"
"@aws-sdk/middleware-recursion-detection" "3.171.0"
"@aws-sdk/middleware-retry" "3.171.0"
"@aws-sdk/middleware-sdk-s3" "3.171.0"
"@aws-sdk/middleware-serde" "3.171.0"
"@aws-sdk/middleware-signing" "3.171.0"
"@aws-sdk/middleware-ssec" "3.171.0"
"@aws-sdk/middleware-stack" "3.171.0"
"@aws-sdk/middleware-user-agent" "3.171.0"
"@aws-sdk/node-config-provider" "3.171.0"
"@aws-sdk/node-http-handler" "3.171.0"
"@aws-sdk/protocol-http" "3.171.0"
"@aws-sdk/signature-v4-multi-region" "3.171.0"
"@aws-sdk/smithy-client" "3.171.0"
"@aws-sdk/types" "3.171.0"
"@aws-sdk/url-parser" "3.171.0"
"@aws-sdk/util-base64-browser" "3.170.0"
"@aws-sdk/util-base64-node" "3.170.0"
"@aws-sdk/util-body-length-browser" "3.170.0"
"@aws-sdk/util-body-length-node" "3.170.0"
"@aws-sdk/util-defaults-mode-browser" "3.171.0"
"@aws-sdk/util-defaults-mode-node" "3.171.0"
"@aws-sdk/util-stream-browser" "3.171.0"
"@aws-sdk/util-stream-node" "3.171.0"
"@aws-sdk/util-user-agent-browser" "3.171.0"
"@aws-sdk/util-user-agent-node" "3.171.0"
"@aws-sdk/util-utf8-browser" "3.170.0"
"@aws-sdk/util-utf8-node" "3.170.0"
"@aws-sdk/util-waiter" "3.171.0"
"@aws-sdk/xml-builder" "3.170.0"
entities "2.2.0"
fast-xml-parser "3.19.0"
tslib "^2.3.1"
"@aws-sdk/client-s3@^3.121.0":
version "3.414.0"
resolved "https://registry.npmmirror.com/@aws-sdk/client-s3/-/client-s3-3.414.0.tgz#246c5f1af0556a08ca42db09fd249f59eb9394bc"
integrity sha512-uEag2GPuuxWmnzOxUhAy0EYo3LW3u/UyCw1IxU3zkaTRQnD6TZ07kjv3Q6Zytqt82yKzJPZInzNNRdtGJdyxbw==
dependencies:
"@aws-crypto/sha1-browser" "3.0.0"
"@aws-crypto/sha256-browser" "3.0.0"
"@aws-crypto/sha256-js" "3.0.0"
"@aws-sdk/client-sts" "3.414.0"
"@aws-sdk/credential-provider-node" "3.414.0"
"@aws-sdk/middleware-bucket-endpoint" "3.413.0"
"@aws-sdk/middleware-expect-continue" "3.413.0"
"@aws-sdk/middleware-flexible-checksums" "3.413.0"
"@aws-sdk/middleware-host-header" "3.413.0"
"@aws-sdk/middleware-location-constraint" "3.413.0"
"@aws-sdk/middleware-logger" "3.413.0"
"@aws-sdk/middleware-recursion-detection" "3.413.0"
"@aws-sdk/middleware-sdk-s3" "3.414.0"
"@aws-sdk/middleware-signing" "3.413.0"
"@aws-sdk/middleware-ssec" "3.413.0"
"@aws-sdk/middleware-user-agent" "3.413.0"
"@aws-sdk/region-config-resolver" "3.413.0"
"@aws-sdk/signature-v4-multi-region" "3.413.0"
"@aws-sdk/types" "3.413.0"
"@aws-sdk/util-endpoints" "3.413.0"
"@aws-sdk/util-user-agent-browser" "3.413.0"
"@aws-sdk/util-user-agent-node" "3.413.0"
"@aws-sdk/xml-builder" "3.310.0"
"@smithy/config-resolver" "^2.0.8"
"@smithy/eventstream-serde-browser" "^2.0.7"
"@smithy/eventstream-serde-config-resolver" "^2.0.7"
"@smithy/eventstream-serde-node" "^2.0.7"
"@smithy/fetch-http-handler" "^2.1.3"
"@smithy/hash-blob-browser" "^2.0.7"
"@smithy/hash-node" "^2.0.7"
"@smithy/hash-stream-node" "^2.0.7"
"@smithy/invalid-dependency" "^2.0.7"
"@smithy/md5-js" "^2.0.7"
"@smithy/middleware-content-length" "^2.0.9"
"@smithy/middleware-endpoint" "^2.0.7"
"@smithy/middleware-retry" "^2.0.10"
"@smithy/middleware-serde" "^2.0.7"
"@smithy/middleware-stack" "^2.0.0"
"@smithy/node-config-provider" "^2.0.10"
"@smithy/node-http-handler" "^2.1.3"
"@smithy/protocol-http" "^3.0.3"
"@smithy/smithy-client" "^2.1.4"
"@smithy/types" "^2.3.1"
"@smithy/url-parser" "^2.0.7"
"@smithy/util-base64" "^2.0.0"
"@smithy/util-body-length-browser" "^2.0.0"
"@smithy/util-body-length-node" "^2.1.0"
"@smithy/util-defaults-mode-browser" "^2.0.8"
"@smithy/util-defaults-mode-node" "^2.0.10"
"@smithy/util-retry" "^2.0.0"
"@smithy/util-stream" "^2.0.10"
"@smithy/util-utf8" "^2.0.0"
"@smithy/util-waiter" "^2.0.7"
fast-xml-parser "4.2.5"
tslib "^2.5.0"
any updates on this issue? facing the same issue as described at the start
Hey all - regarding the issue you're experiencing, the comment above suggests a potential solution. The root cause seems to be related to the need for transpiling the AWS SDK code to ensure compatibility with your environment or desired target..
As a workaround, you manually transpiled AWS-SDK folder, and this resolved the errors you were encountering. Specifically, you ran the following command from the root directory of your project:
npx babel node_modules/@aws-sdk --out-dir node_modules/@aws-sdk --presets=@babel/preset-env
Let us know if issue persists after trying the workaround.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.
Checkboxes for prior research
Describe the bug
I am using Electron, and the following error is shown on running the "npm start" command. Any suggestions or anyone has ever faced a similar issue?
some dependencies
webpack config
Added the above code to resolve the following error
SDK version number
3.292.0
Which JavaScript Runtime is this issue in?
Node.js
Details of the browser/Node.js/ReactNative version
14.16.0
Reproduction Steps
Error caused by running the "npm start" command
Observed Behavior
Expected Behavior
The project should run as normal. But getting the mentioned errors
Possible Solution
No response
Additional Information/Context
No response