3

I'm writing Jest tests for some react components, which are in a Create-React-App project that is using Typescript. However, when running my test-suite, I come across an error that doesn't allow any component that is using apollo-boost-upload to run.

    TypeError: Cannot redefine property: __esModule
        at Function.defineProperty (<anonymous>)

    >  7 | import { gql } from 'apollo-boost-upload';
         | ^

      at node_modules/apollo-boost-upload/dist/index.cjs.js:165:33
          at Array.forEach (<anonymous>)
      at Object.<anonymous> (node_modules/apollo-boost-upload/dist/index.cjs.js:164:27)
      at Object.<anonymous> (src/<component-with-apollo-upload-boost>/index.tsx:7:1)
      at Object.<anonymous> (src/<component-to-test-using-above-component-with-apollo-boost>/index.tsx:6:1)
      at Object.<anonymous> (src/<component-to-test-using-above-component-with-apollo-boost>/__tests__/index-test.tsx:3:1)

I would also share the test file, but the error is stemming from a component that is not directly being tested, and because this is an import error, there's no test code running before it throws.

Is there a way to get around this error, and if not, what is a prescribed way to utilize Apollo Boost in a Typescript CRA app that uses Jest?

skyboyer
  • 22,209
  • 7
  • 57
  • 64
Johnnie
  • 197
  • 1
  • 9

0 Answers0