Guy
Guy

Reputation: 67260

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...

Upvotes: 7

Views: 2681

Answers (3)

Shailendra Kumar
Shailendra Kumar

Reputation: 11

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

    {
        "presets": [
            [

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

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

<!-- end snippet -->

Upvotes: 1

Yogesh Devgun
Yogesh Devgun

Reputation: 1557

Try adding/updating .babelrc

with

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "targets": {
          "node": "current"
        }
      }
    ]
  ]
}

Upvotes: 0

James Garcia
James Garcia

Reputation: 186

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.

Upvotes: 2

Related Questions