Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest seems not working with babel v7 #5736

Closed
dnepro opened this issue Mar 6, 2018 · 15 comments
Closed

Jest seems not working with babel v7 #5736

dnepro opened this issue Mar 6, 2018 · 15 comments

Comments

@dnepro
Copy link

dnepro commented Mar 6, 2018

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)

@dnepro
Copy link
Author

dnepro commented Mar 6, 2018

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 ✌️

@SimenB
Copy link
Member

SimenB commented Mar 6, 2018

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

yes

@SimenB SimenB closed this as completed Mar 6, 2018
@bzmw
Copy link

bzmw commented Mar 9, 2018

Why both babel-core and @babel/core, is there a tracking issue for the package that is referring to babel-core?

@SimenB
Copy link
Member

SimenB commented Mar 9, 2018

@marcinczenko
Copy link

marcinczenko commented May 1, 2018

Just upgraded babel from 7.0.0-beta.44 to 7.0.0-beta.46 and all my tests fail with Unexpected token import. Looks like .babelrc is ignored. Is it known issue?

I see babel changes the way .babelrc files are discovered and it introduces babel.config.js, but I could not find any documentation. See:

https://github.com/babel/babel/releases/tag/v7.0.0-beta.45

and

babel/babel#7784

@SimenB
Copy link
Member

SimenB commented May 1, 2018

That's #6053

@marcinczenko
Copy link

Thanks - will check it out.

@hannadrehman
Copy link

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; 

@silverbackdan
Copy link

@hannadrehman I just had this issue and it worked in my docker container, I think it's the version of yarn that will cause this. 1.6.0 results in your issue, 1.7.0 seems to work well.

@dancon
Copy link

dancon commented Nov 26, 2018

@hannadrehman i have the same issue.

@steveinatorx
Copy link

steveinatorx commented Feb 6, 2019

had similar issue - i could not get jest 24 to work with any combination of babel 7 when using latest yarn. i had to switch back to npm install which seemed to properly set up the dependent package hoisting.

@SimenB
Copy link
Member

SimenB commented Feb 6, 2019

Jest 24 does not need the bridge at all

@steveinatorx
Copy link

steveinatorx commented Feb 6, 2019

pardon me. the bridge package was likely one of the many package combinations i tried to get jest 24 to work with babel 7. what worked for me was installing both @babel/core": "^7.2.2" and "babel-core": "^7.0.0-0", and switching from yarn to npm. i've edited the above comment to not include bridge package.

@viT-1
Copy link

viT-1 commented Mar 8, 2019

@hannadrehman
I have the similar issue - tests failed with

TypeError: require(...) is not a function

It's happens after configuring @babel/polyfill https://babeljs.io/docs/en/babel-polyfill.

...
"@babel/core": "^7.2.2",
"babel-jest": "^24.1.0",
"jest": "^24.1.0",
...

Solved by changing { useBuiltIns: 'usage' } to { useBuiltIns: 'entry' }

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants