Jest: Cannot find module 'core-js/modules/es6.regexp.split'

Created on 20 May 2019  路  7Comments  路  Source: facebook/jest

馃悰 Bug Report

Using any of the modules provided my core-js/packages returns this error. Jest targets the old structure of core-js

Screen Shot 2019-05-20 at 11 34 22 PM

To Reproduce

  • yarn add core-js -D

defineStack.js

const defineStack = (stack) => {
  // Converting the exisiting string trace into an array
  stack = stack.split('\n');

  // Removing the first 2 elements of the array
  for (let i = 0; i < 3; ++i) {
    stack.shift();
  }

  // Returning the value of this.stack to the required stack trace
  return stack.join('\n').trim();
}

export default defineStack;

__tests__/defineStack.js

import defineStack from '../defineStack';

test('trims the stack and returns proper information', () => {
  console.log(defineStack);
});

Expected behavior

The tests should pass and log the function definition

Run npx envinfo --preset jest

  System:
    OS: macOS 10.14.4
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
  Binaries:
    Node: 10.15.0 - /usr/local/bin/node
    Yarn: 1.16.0 - ~/.yarn/bin/yarn
    npm: 6.9.0 - ~/.npm-packages/bin/npm
  npmPackages:
    jest: ^24.8.0 => 24.8.0 
Bug Report Needs Repro Needs Triage

Most helpful comment

@AmaanKulshreshtha Babel currently assumes you are using corejs@2. You should be able to add corejs: 3 to your @babel/preset-env options to fix this 馃槂

e.g.

{
  presets: [
    [
      '@babel/env',
      {
        targets: {
          // ...
        },
        useBuiltIns: 'usage',
        corejs: 3
      }
    ]
}

All 7 comments

According to the change log of core-js v3.0

  • Move all features from ES5, ES2015, ES2016, ES2017, ES2018 and ES2019 to one namespace for stable ES - it's available as core-js/es, all those features in modules folder has es. prefix.

  • Change prefix for ES proposals from es7. to esnext., they no longer available in core-js/es7, use core-js/stage/* instead of that.

Downgrading it to v2.6.5 solves my tests issue, but I want to keep the dependency up to date for compatibility with other packages.

@AmaanKulshreshtha Babel currently assumes you are using corejs@2. You should be able to add corejs: 3 to your @babel/preset-env options to fix this 馃槂

e.g.

{
  presets: [
    [
      '@babel/env',
      {
        targets: {
          // ...
        },
        useBuiltIns: 'usage',
        corejs: 3
      }
    ]
}

The solution works....thanks so much!!

Although I would like to know how does jest work with babel, I haven't installed the babel-jest package....? 馃

Strange, not particularly familiar with Jest internals so can't comment on that. Perhaps create a minimal repro for one of the maintainers to look at assuming this isn't expected behaviour.

Not sure how long it's been this way (a long time I think), but Jest comes with babel-jest in the dependency tree and it is preconfigured as a transform. Not sure if there's a reason we still recommend installing babel-jest explicitly in places in the docs @SimenB

We need babel to have test coverage and mocks, which is why it's on by default.


You need it to live at the top level of node_modules. It being hoisted by the package manager is an implementation detail.


Jest has bundled babel-jest for ~10 versions


That said, this issue is about babel configuration, it's not an issue with Jest.

I have the same issue now and I've been searching for two days.
Screen Shot 2019-07-29 at 9 57 30 PM

Seems that jest.mock not working.

Screen Shot 2019-07-29 at 9 58 02 PM

I've installed babel-jest as dev-depen and core-js 3.0 as dependency.

Hope you guys could check this out. I would appreciate very much.

Was this page helpful?
0 / 5 - 0 ratings