Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest 24.0.0 Plugin/Preset files are not allowed to export objects, only functions

After upgrading from Jest 23.6.0 to 24.0.0 I'm getting this error: Plugin/Preset files are not allowed to export objects, only functions.

This is caused by this commit: https://github.com/facebook/jest/pull/7203/files which documents the breaking change.

For those of us using require, it's not clear on what change we need to make in our repos to fix this.

There are a number of similar questions here on Stack Overflow but none of them have lead me to the solution yet...

like image 298
Guy Avatar asked Jan 26 '19 15:01

Guy


2 Answers

Recently I had the same issue working with Jest 24.0.0. This is what I did to have it running.

First I installed the dependencies as they explain in the docs, but I used npm insted of yarn.

  npm install --save-dev babel-jest @babel/core @babel/preset-env

Then I had to add a file called babel.config.js with this content:

// babel.config.js
module.exports = {
  presets: [
    [
      '@babel/preset-env',
      {
        targets: {
          node: 'current',
        },
      },
    ],
  ],
};

And then it started to work correclty. I hope this can help.

like image 92
James Garcia Avatar answered Sep 24 '22 15:09

James Garcia


presets[0][1] must be an object. ================ important

    {
        "presets": [
            [

                "env",
                {
                    "targets": {
                        "node": "current"
                    }
                },

                "react"
            ]
        ],
        "plugins": [
            "transform-object-rest-spread",
            "transform-class-properties"
        ]
    }

<!-- end snippet -->
like image 43
Shailendra Kumar Avatar answered Sep 25 '22 15:09

Shailendra Kumar