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

Unexpected token 'export' when using @aws-sdk with Jest #271

Closed
swelham opened this issue May 27, 2022 · 11 comments
Closed

Unexpected token 'export' when using @aws-sdk with Jest #271

swelham opened this issue May 27, 2022 · 11 comments
Labels
question Further information is requested

Comments

@swelham
Copy link

swelham commented May 27, 2022

I have created a new worker using npx wrangler init with typescript. I am using the @aws-sdk/client-eventbridge package in my worker. However, when I try and mock it in tests using aws-sdk-client-mock I get the following error.

.../node_modules/uuid/dist/esm-browser/index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export { default as v1 } from './v1.js';

This appears to be an ES module issue and only occurs when I have new EventBridgeClient({}) in my test code.

My jest config looks like this.

module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'miniflare',
};

If I change testEnvironment to node, the error no longer occurs and the test will pass. However, I loose the miniflare benefits in jest.

Is there something I'm missing here to get this working with the miniflare test environment?

@mrbbot
Copy link
Contributor

mrbbot commented Jun 9, 2022

Hey! 👋 Which version of jest and jest-environment-miniflare are you using? It's possible upgrading to jest@28 and jest-environment-miniflare@2.5.0 might fix this issue.

@mrbbot mrbbot added the question Further information is requested label Jun 9, 2022
@swelham
Copy link
Author

swelham commented Jun 9, 2022

Hey. I'm on jest@28.1.0 and jest-environment-miniflare@2.5.0 and still seeing the above issue.

Interestingly I have been able to work around it by mocking the uuid library in tests like this.

jest.mock('uuid', () => 'eb7b7961-395d-4b4c-afc6-9ebcadaf0150');

Not ideal, but helps me out in my case. Though this would become an issue I guess if I wanted to directly use uuid in my worker without having to supply a mock.

@thienna
Copy link

thienna commented Jun 15, 2022

same issue

1 similar comment
@tmizuma
Copy link

tmizuma commented Jul 15, 2022

same issue

@esther44
Copy link

same issue, has anyone found a solution?

@cyberdude
Copy link

Same issue

@andreMycroft
Copy link

Same

@andreMycroft
Copy link

microsoft/accessibility-insights-web#5421 (comment)

This solve my problem create a resolver. the uuid has a incompatibility with jest.

@maxy4u
Copy link

maxy4u commented Sep 21, 2022

What is the solution for this issue ? i am on jest 29.0 and have the same issue.

@mkbctrl
Copy link

mkbctrl commented Sep 22, 2022

@maxy4u as @andreMycroft mentioned, the resolver. He could be a little bit more specific I guess 😝 :
microsoft/accessibility-insights-web@9ad4e61

@maxy4u
Copy link

maxy4u commented Sep 23, 2022

@maxy4u as @andreMycroft mentioned, the resolver. He could be a little bit more specific I guess 😝 : microsoft/accessibility-insights-web@9ad4e61

Thank you @mkbctrl I will try this. :)

@mrbbot mrbbot closed this as completed Oct 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
Archived in project
Development

No branches or pull requests

9 participants