Search code examples
reactjsreact-nativeunit-testingjestjs

TypeError: Cannot destructure property 'instrument' of 'options' as it is undefined


I am trying to install jest testing in my visual studio code. I ran into the following errors. Can you please help me with this problem?

● Test suite failed to run

TypeError: Cannot destructure property 'instrument' of 'options' as it is undefined.

  at Object.getCacheKey (node_modules/fbjs-scripts/jest/createCacheKeyFunction.js:35:12)
  at ScriptTransformer._getCacheKey (node_modules/@jest/transform/build/ScriptTransformer.js:280:41)
  at ScriptTransformer._getFileCachePath (node_modules/@jest/transform/build/ScriptTransformer.js:351:27)
  at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:588:32)
  at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:758:40)
  at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:815:19)

Solution

  • For me, this started happening after I upgraded to jest version 27. Pinning its version to 26.6.3. I.e.: npm i -D [email protected] solved the issue.

    In case you use typescript and ts-jest use: npm i -D [email protected] [email protected]