TypeError: Object.values ​​is not a function - how to properly polyfill with babel-preset-env for fun?

I got the following error after upgrading to Jest v20, where they deleted automatic babel-polyfilldue to memory leaks:

TypeError: Object.values is not a function

I understand that I need polyfill this on my own, I use babel-preset-envand have the following file .babelrc:

  "env": {
    "development": {
      "plugins": ["transform-react-jsx-source"]
    },
    "test": {
      "presets": [
        "react",
        "stage-3",
        ["env", {
          "targets": {
            "browsers": [
              "firefox >= 36",
              "chrome >= 38",
              "opera >= 25",
              "safari >= 9",
              "ios >= 9"
            ],
            "node": "6.11.4"
          },
          "useBuiltIns": "usage",
          "include": ["es7.object.values"],
          "debug": true
        }],
        "jest"
      ],
      "plugins": [
        "transform-class-properties"
      ],
    }
  }

I see what es7.object.valuesfills in the debug output:

Using polyfills:
  ...
  es7.object.values {"chrome":"38","firefox":"36","ios":"9","safari":"9","node":"6.11.4"}

But I still get the error message, help!

+4
source share
1 answer

Some of the options are:

  • bump node version to supporting Object.values(which seems to be 7.0judging by this answer )
  • polyfill, babel-polyfill ( import 'babel-polyfill' setupTests.js).
+1

Source: https://habr.com/ru/post/1687385/


All Articles