babel: TypeError: wks is not a function with babel7. Used to work perfectly with Babel6

Describe the regression My tests with jest started failing due to a babel transpilation error after upgrading to Babel7. Tests were running perfectly in babel6. I tried debugging but could not find the source of the error. Upgrades were done using babel-upgrade.

Note: I have also tried removing transform-regenerator and regenerator-runtime but am getting the same error.

Error

TypeError: wks is not a function

      at Object.<anonymous>.module.exports (node_modules/core-js/modules/_fix-re-wks.js:16:16)
      at Object.<anonymous> (node_modules/core-js/modules/es6.regexp.replace.js:4:25)
      at Object.<anonymous> (node_modules/core-js/modules/es6.regexp.split.js:3:1)
      at Object.<anonymous> (node_modules/core-js/modules/es6.symbol.js:7:1)
      at Object.<anonymous> (node_modules/core-js/modules/_is-object.js:5:1)
      at Object.<anonymous> (node_modules/core-js/modules/_inherit-if-required.js:3:16)
      at Object.<anonymous> (node_modules/core-js/modules/es6.regexp.constructor.js:5:25)
      at Object.<anonymous> (node_modules/core-js/modules/es6.regexp.match.js:3:1)
      at Object.<anonymous> (node_modules/core-js/modules/es6.function.name.js:3:1)
      at Object.<anonymous> (node_modules/core-js/modules/_wks.js:3:1)
      at Object.<anonymous> (node_modules/core-js/modules/_add-to-unscopables.js:4:19)
      at Object.<anonymous> (node_modules/core-js/modules/es6.array.iterator.js:3:24)
      at Object.<anonymous> (node_modules/core-js/modules/web.dom.iterable.js:3:18)
      at Object.<anonymous> (node_modules/regenerator-runtime/runtime.js:3:1)

Input Code Babel Configuration (.babelrc, package.json, cli command) babel.config.js

module.exports = {
    "presets": [
        [
            "@babel/preset-env",
            {
                "targets": {
                    "ie": 11
                    // "browsers": ["last 2 versions"]
                },
                "useBuiltIns": "usage"
            }
        ],
        "@babel/preset-react"
    ],
    "plugins": [
        "@babel/plugin-transform-regenerator",
        "@babel/plugin-syntax-dynamic-import",
        "@babel/plugin-syntax-import-meta",
        "@babel/plugin-proposal-class-properties",
        "@babel/plugin-proposal-json-strings",
        [
            "@babel/plugin-proposal-decorators",
            {
                "legacy": true
            }
        ],
        "@babel/plugin-proposal-function-sent",
        "@babel/plugin-proposal-export-namespace-from",
        "@babel/plugin-proposal-numeric-separator",
        "@babel/plugin-proposal-throw-expressions",
        "@babel/plugin-proposal-object-rest-spread",
        "@babel/plugin-transform-object-assign"
    ]
};

package.json

"devDependencies": {
    "@babel/cli": "^7.0.0",
    "@babel/core": "^7.0.1",
    "@babel/plugin-proposal-class-properties": "^7.0.0",
    "@babel/plugin-proposal-decorators": "^7.0.0",
    "@babel/plugin-proposal-export-namespace-from": "^7.0.0",
    "@babel/plugin-proposal-function-sent": "^7.0.0",
    "@babel/plugin-proposal-json-strings": "^7.0.0",
    "@babel/plugin-proposal-numeric-separator": "^7.0.0",
    "@babel/plugin-proposal-object-rest-spread": "^7.0.0",
    "@babel/plugin-proposal-throw-expressions": "^7.0.0",
    "@babel/plugin-syntax-dynamic-import": "^7.0.0",
    "@babel/plugin-syntax-import-meta": "^7.0.0",
    "@babel/plugin-transform-object-assign": "^7.0.0",
    "@babel/plugin-transform-regenerator": "^7.0.0",
    "@babel/preset-env": "^7.0.0",
    "@babel/preset-react": "^7.0.0",
    "babel-core": "7.0.0-bridge.0",
    "babel-loader": "^8.0.0",
    "enzyme": "^3.3.0",
    "enzyme-adapter-react-16": "^1.1.1",
    "enzyme-to-json": "^3.3.1",
    "exports-loader": "0.6.4",
    "imports-loader": "0.7.1",
    "jasmine": "^2.8.0",
    "jest": "^23.4.1",
    "jest-cli": "^23.4.1",
    "jest-trx-results-processor": "^0.0.7",
    "regenerator-runtime": "^0.12.1",
  },
  "dependencies": {
    "@babel/polyfill": "^7.0.0",
    "@babel/runtime": "^7.0.0",
    "babel-jest": "^23.6.0",
    "babel-plugin-add-module-exports": "^0.2.1"
  },

jest config

{

    "unmockedModulePathPatterns": [
      "<rootDir>/node_modules/react",
      "<rootDir>/node_modules/react-dom",
      "<rootDir>/node_modules/react-addons-test-utils",
      "<rootDir>/node_modules/fbjs",
      "enzyme"
    ],
    "roots": [
      "<rootDir>/__tests__"
    ],
    "transformIgnorePatterns": [
      "node_modules/(^generic-)/i",
      "node_modules/react-infinite-scroller"
    ],
    "setupFiles": [
      "./jestsetup.js"
    ],
    "snapshotSerializers": [
      "enzyme-to-json/serializer"
    ],
    "testResultsProcessor": "./jestTrxProcessor",
    "verbose": true
  }

Expected behavior/code transpilation should work correctly and tests should run as they used to do in babel6

Environment

  • Babel version(s): 7.1.0
  • Node/npm version: [e.g. Node 10.10.0/npm 6.4.1/yarn 1.9.4]
  • OS: [e.g. OSX 10.13.6, Windows 10]
  • Monorepo no
  • How you are using Babel: jest, cli

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (5 by maintainers)

Most upvoted comments

@loganfsmyth this reason why I have this pattern is because packages that start with generic- are internal packages that are not pre-compiled and would have to be compiled before jest runs its tests. The same goes with react-infinite-scroller.

I tried adding ignore: [/\/core-js/] but now I am getting this error

TypeError: (0 , _typeof4.default) is not a function
      at _typeof2 (node_modules/@babel/runtime/helpers/typeof.js:12:60)
      at _typeof (node_modules/@babel/runtime/helpers/typeof.js:26:39)
      at node_modules/regenerator-runtime/runtime.js:718:84
      at Object.<anonymous> (node_modules/regenerator-runtime/runtime.js:719:2)

I even tried removing useBuiltIns: usage but I still get the error. What can I do to pre-compile those dependencies + not add core-js everywhere.

Also what is funny is that jest used to work perfectly with babel6 under these configurations. What changed in Babel7?

Thanks for your help!

@salmankhann The issue is that you are compiling node_modules and since you’re using usage, you’re going to add imports for core-js into random dependencies. In this case, you’re actually going to insert imports for core-js into core-js itself, causing dependency cycles and errors like this one.

Is there a reason you’re specifically compiling node_modules with:

    "transformIgnorePatterns": [
      "node_modules/(^generic-)/i",
      "node_modules/react-infinite-scroller"
    ],

The easiest fix in this case is to add ignore: [/\/core-js/] to your Babel config to skip compilation of core-js.