Upgrade to SDK 31 Jest test fails with Requires Babel "^7.0.0-0", but was loaded with "6.26.3".

Happens both on my build and on a fresh expo init build. In my build it just complains about version numbers. In fresh expo init, it complains about /node_modules/react-native/jest/mockComponent.js having unexpected tokens at static displayName = 'Component';

    Requires Babel "^7.0.0-0", but was loaded with "6.26.3". If you are sure you have a compatible version of @babel/core, it is likely that something in your build process is loading the wrong version. Inspect the stack trace of this error to look for the first entry that doesn't mention "@babel/core" or "babel-core" to see what is calling Babel. (While processing preset: "/node_modules/babel-preset-expo/index.js")

      at throwVersionError (node_modules/@babel/helper-plugin-utils/lib/index.js:65:11)
      at Object.assertVersion (node_modules/@babel/helper-plugin-utils/lib/index.js:13:11)
      at _default (node_modules/@babel/plugin-proposal-decorators/lib/index.js:35:7)
      at node_modules/@babel/helper-plugin-utils/lib/index.js:19:12
      at Function.memoisePluginContainer (node_modules/babel-core/lib/transformation/file/options/option-manager.js:113:13)
      at Function.normalisePlugin (node_modules/babel-core/lib/transformation/file/options/option-manager.js:146:32)
      at node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30
          at Array.map (<anonymous>)
      at Function.normalisePlugins (node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
      at OptionManager.mergeOptions (node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36)
      at node_modules/babel-core/lib/transformation/file/options/option-manager.js:265:14
      at node_modules/babel-core/lib/transformation/file/options/option-manager.js:323:22
          at Array.map (<anonymous>)
      at OptionManager.resolvePresets (node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
      at OptionManager.mergePresets (node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
      at OptionManager.mergeOptions (node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
      at OptionManager.init (node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
      at File.initOptions (node_modules/babel-core/lib/transformation/file/index.js:212:65)
      at new File (node_modules/babel-core/lib/transformation/file/index.js:135:24)
      at Pipeline.transform (node_modules/babel-core/lib/transformation/pipeline.js:46:16)
{
    "name": "...",
    "main": "./node_modules/expo/AppEntry.js",
    "scripts": {
        "start": "expo start",
        "android": "expo start --android",
        "ios": "expo start --ios",
        "eject": "expo eject",
        "test": "jest",
        "testwatch": "jest --watch"
    },
    "devDependencies": {
        "babel-plugin-transform-remove-console": "^6.9.4",
        "babel-preset-expo": "^5.0.0",
        "eslint": "^5.2.0",
        "eslint-config-airbnb": "^17.0.0",
        "eslint-config-expo": "^6.0.0",
        "eslint-plugin-import": "^2.13.0",
        "eslint-plugin-jsx-a11y": "^6.1.1",
        "eslint-plugin-react": "^7.10.0",
        "eslint-plugin-react-native": "^3.2.1",
        "jest-expo": "^31.0.0",
        "jest-fetch-mock": "^1.7.5",
        "prettier": "^1.13.7",
        "react-test-renderer": "16.2.0"
    },
    "jest": {
        "preset": "jest-expo",
        "verbose": true
    },
    "dependencies": {
        "expo": "^31.0.4",
        "react": "16.5.0",
        "react-native": "https://github.com/expo/react-native/archive/sdk-31.0.1.tar.gz",
        "react-native-app-link": "^0.4.1"
    }
}

Fresh install throws errors about Jest’s mockComponent.js
https://github.com/expo/expo/issues/2950

I am receiving the same error, with this additional piece of information:

(While processing preset: "/Users/my_name/company_name/project_name/node_modules/babel-preset-expo/index.js")

I found a solution for now, that allows me to start testing. This is the first time I am trying to test my app, so I had no previous configs. I removed any references to babel or Jest out of my package.json, then rm -rf node_modules to make sure they were clean, and then installed all of my node_modules again with yarn install followed by installing Jest-Expo.

yarn add --dev jest-expo

I also changed my .babelrc file name to babel.config.js and changed the code in that file to

  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
    plugins: [
      [
        '@babel/transform-runtime',
        {
          regenerator: true,
        },
      ],
    ],
  };
}

In my package.json I also added:

"scripts": {
    "test": "node_modules/.bin/jest"
 },
"jest": {
    "preset": "jest-expo"
  },

It is now working as expected.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.