question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:8
  • Comments:11

github_iconTop GitHub Comments

3reactions
andreMycroftcommented, Aug 9, 2022

https://github.com/microsoft/accessibility-insights-web/pull/5421#issuecomment-1109168149/

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

2reactions
mkbctrlcommented, Sep 22, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest gives an error: "SyntaxError: Unexpected token export"
This means, that a file is not transformed through TypeScript compiler, e.g. because it is a JS file with TS syntax, or it...
Read more >
nx jest unexpected token 'export' - You.com | The AI Search ...
Current Behavior. The error Jest encountered an unexpected token when writing a test for a library that depends on another library, coming from...
Read more >
Mocking modular AWS SDK for JavaScript (v3) in Unit Tests
But we keep it short and simple to focus on our tests. Example code for unit testing. All the examples below use Jest...
Read more >
stryker-mutator/stryker - Gitter
And the unexpected token is in the line: import { shallowMount } from "@vue/test-utils";. I have configured Stryker to use my Jest config.js...
Read more >
Jest: Unexpected Token Export With React-Navigation
Unexpected token is similar to syntax error but more specific. react-color on gitmemory. cd react-node-boilerplate npm i aws-sdk multer-s3 multer path.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found