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

util-user-agent-node and signature-v4-multi-region fails with ESM #4373

Closed
3 tasks done
ciscoheat opened this issue Jan 26, 2023 · 4 comments · Fixed by #5203
Closed
3 tasks done

util-user-agent-node and signature-v4-multi-region fails with ESM #4373

ciscoheat opened this issue Jan 26, 2023 · 4 comments · Fixed by #5203
Assignees
Labels
bug This issue is a bug. investigating Issue is being investigated and/or work is in progress to resolve the issue. p3 This is a minor priority issue

Comments

@ciscoheat
Copy link

Checkboxes for prior research

Describe the bug

In version 3.257.0 I suddenly get an ESM-related error when using vitest with a SvelteKit site. By configuring vite to inline the packages, it works again.

SDK version number

@aws-sdk/[email protected]

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

v18.10.0

Reproduction Steps

Sorry but I cannot reproduce this in an easy way. I'm hoping that the error is well-known and has an easy fix.

Observed Behavior

SyntaxError: Cannot use import statement outside a module
 ❯ Object.compileFunction node:vm:360:18

Module .../node_modules/.pnpm/@[email protected]/node_modules/@aws-sdk/util-user-agent-node/dist-es/is-crt-available.js:1 seems to be an ES Module but shipped in a CommonJS package. You might want to create an issue to the package "@aws-sdk/util-user-agent-node" asking them to ship the file in .mjs extension or add "type": "module" in their package.json.

As a temporary workaround you can try to inline the package by updating your config:

// vitest.config.js
export default {
  test: {
    deps: {
      inline: [
        "@aws-sdk/signature-v4-multi-region"
      ]
    }
  }
}

Expected Behavior

No error message, it used to work fine.

Possible Solution

No response

Additional Information/Context

The suggested workaround works, when adding this to vite.config.js

import { defineConfig } from 'vite';

export default defineConfig(({ command }) => {
  return {
    test: {
      deps: {
        inline: ['@aws-sdk/util-user-agent-node', '@aws-sdk/signature-v4-multi-region']
      }
    }
  }
}
@ciscoheat ciscoheat added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 26, 2023
@RanVaknin
Copy link
Contributor

RanVaknin commented Jan 26, 2023

Hi @ciscoheat ,

Thanks for opening this issue.

Since you are using a 3rd party tool, and we don't have repro steps this will make it hard to root cause.

suddenly get an ESM-related error when using vitest with a SvelteKit site. By configuring vite to inline the packages, it works again.

This being a sudden change is worrisome, this might be a breaking change from the SDK side.
Can you help us somehow reproduce this error? Perhaps a minimal setup, or an explanation of how you are using the SDK in this case? Are you importing that @aws-sdk/signature-v4-multi-region directly?

Thank you,
Ran

@RanVaknin RanVaknin removed the needs-triage This issue or PR still needs to be triaged. label Jan 26, 2023
@RanVaknin RanVaknin self-assigned this Jan 26, 2023
@RanVaknin RanVaknin added the response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. label Jan 26, 2023
@ciscoheat
Copy link
Author

Hello Ran, it is difficult to reproduce. By just adding the @AWS-SDK library to an empty project gives no problem. And the build works without error with SvelteKit, but when testing it with Vitest, the error occurs, even though they are using the same configuration (both are built on Vite).

I'm not importing any of the mentioned libraries, this is my only reference, in a single file:

import { S3Client, PutObjectCommand, DeleteObjectCommand } from '@aws-sdk/client-s3';

And to make things more confusing, there is no reference to this file in the tests.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. label Jan 28, 2023
@RanVaknin RanVaknin added the investigating Issue is being investigated and/or work is in progress to resolve the issue. label Jan 30, 2023
@RanVaknin RanVaknin added the p3 This is a minor priority issue label Feb 7, 2023
@danielzting
Copy link

I am getting the same error on @aws-sdk/client-s3 v3.267.0

If you would like to investigate the commit is here. It only popped up when I imported from @aws-sdk/client-s3 in the file under test.

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. investigating Issue is being investigated and/or work is in progress to resolve the issue. p3 This is a minor priority issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants