Cannot run jest with react-native: TypeError: Cannot destructure property `instrument` of 'undefined' or 'null'

Viewed 2194

I upgraded a react native project from 0.57.8 to 0.63.4

Before the upgrade my jest tests were passing. Now I can't run any of them, even if I take them all out and put this only this in foo.test.js:

describe("helpers", () => {
  it("passes", () => expect(1).toEqual(1));
});

relevant parts of package.json:

{
  "name": "x",
  "version": "8.2.0",
  "private": true,
  "scripts": {
    ...
    "test": "jest  ./src/",
  },
  "jest": {
    "preset": "react-native"
  },
  "dependencies": {
    "@babel/runtime": "^7.5.5",
    ...
    "babel-jest": "^27.0.6",
    ...
    "jest": "^27.0.6",
    "jest-cli": "^27.0.6",
    "react-native": "0.63.4",
    "react-native-cli": "^2.0.1",
    ...
  },
  "devDependencies": {
    "@babel/core": "^7.8.4",
    "@babel/plugin-proposal-class-properties": "^7.14.5",
    "@babel/runtime": "^7.8.4",
    ...
  },
}

When I run the test:

$ npm test

> jest  ./src/

 FAIL  src/lib/foo.test.js
  ● Test suite failed to run

    TypeError: Cannot destructure property `instrument` of 'undefined' or 'null'.

      at Object.getCacheKey (node_modules/fbjs-scripts/jest/createCacheKeyFunction.js:35:34)
      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)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.369 s
Ran all test suites matching /.\/src\//i.
1 Answers

See here, for a PR referencing this issue which I think will fix the problem for you.

Related