Error when using s3-sync-client and @aws-sdk/client-s3 with webpack in Electron project
Asked Answered
S

1

6

I am working on an Electron project and I have configured webpack for it. I recently installed s3-sync-client and @aws-sdk/client-s3 using npm, but when I try to run the project, I get the following error in the console:

[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

Error Image Link

I have checked my webpack configuration and I have loaders set up for other file types, but it seems that these packages are not being handled correctly. Can anyone help me with this issue?

Here is a link to my repository for reference.

Thanks in advance for any help!

I tried to make the changes in the webpack accordingly. But nothing seems to work.

Seignior answered 22/3, 2023 at 11:37 Comment(2)
I've got the same issue with "client-textract"Dissuasive
No, not yet. But I've decided to wrap the Textract function in an AWS Lambda function, seems to be a bit better for me.Dissuasive
A
4

I figured it out using chatGpt. But this is actually tested, so it really works.

Use this webpack config for the js parsing rule:

  { 
    test: /\.js$/,
    exclude: /node_modules\/(?!(aws-sdk|@aws-sdk)\/).*/,
    use: {
      loader: 'babel-loader',
      options: {
        presets: ['@babel/preset-env']
      }
    }
  },

We use a negative lookahead (?!(aws-sdk|@aws-sdk)/) to match all node_modules directories that do not start with "aws-sdk/" or "@aws-sdk/". The .* at the end matches any remaining characters in the path. This will exclude all node_modules directories except for the AWS SDK packages.

I am not sure why AWS is not shipping transpiled js files, but like this we are telling webpack to transpile it for us.

Assurance answered 30/3, 2023 at 8:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.