jest: Jest seems not working with babel v7

Do you want to request a feature or report a bug? bug

What is the current behavior? I get an TypeError: Cannot read property 'loose' of undefined (While processing preset: "/Users/x/Desktop/jest-test/node_modules/babel-preset-react-app/index.js") on using jest v22.4.2 with babel v7

I’ve searched for this error and found this Bug in Babel, which suggests that when babel-core instead of @babel/core is required by any package, it will break. And it seems like jest-runtime v22.4.2 (currently the newest one) is doing exactly this.

If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install and yarn test. I created this GitHub Repo

What is the expected behavior? No error and it works with babel v7

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.

  • Operating System: MacOS 10.13.2 (High Sierra)
  • Nodejs: v9.4.0
  • npm: v5.7.1

(all other dependencies can be found in the aforementioned GitHub Repo)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (4 by maintainers)

Most upvoted comments

same issue. i have @babel/core and babel-core@^7.0.0-0 installed. the strange thing is when i try to use .babelrc' it works. but when i use babel.config.jsit dosent work in that case. here is mybabel.config.js`

  const babelConfig = (api) => {
  // api.cache.never();
  const config = {
    presets: [
      ['@babel/preset-env', { modules: false, useBuiltIns: 'usage' }],
      '@babel/preset-react',
    ],
    plugins: [
      'react-hot-loader/babel',
      '@babel/plugin-proposal-object-rest-spread',
      '@babel/plugin-proposal-class-properties',
      '@babel/plugin-syntax-dynamic-import',
      ['import', { libraryName: 'antd', libraryDirectory: 'es', style: false }],
      [
        'module-resolver',
        {
          root: [
            './src',
          ],
          alias: {
            App: './src/App',
            Common: './src/App/Common',
            Elements: './src/App/Elements',
            Router: './src/App/Router',
            Constants: './src/Constants',
            Services: './src/Services',
            Store: './src/Store',
            Styles: './src/Styles',
            Assets: './src/Assets',
          },
        },
      ],
    ],
  };
  if (api.env('test')) {
    config.presets.splice(0, 1, ['@babel/preset-env', { useBuiltIns: 'usage' }]); // if i remove this nothing changes
    config.plugins.push('@babel/plugin-transform-modules-commonjs');
  }
  return config;
};

module.exports = babelConfig; 

Ahh forget it, in the Docs its npm install --save-dev babel-jest 'babel-core@^7.0.0-0' @babel/core regenerator-runtime, so both babel-core and @babel-core need to be installed 🤐 must have missed that, sorry ✌️

so both babel-core and @babel-core need to be installed

yes