Jest Test Babel Error: Plugin/Preset files are not allowed to export objects

余生长醉 提交于 2019-12-01 03:40:52

babel bridge is meant to cover any issues between 6 and 7

That is 100% not what the bridge package does. All it does is allow tools that use babel-core to pass through to @babel/core. The entire package is this single line of code.

If you are using @babel/core, you need to use plugins that work on Babel 7. That means babel-preset-react should be changed to @babel/preset-react and same for @babel/preset-env and your .babelrc should be:

{
  "presets": [
    "@babel/env",
    "@babel/react",
  ]
}

Similarly, babel-polyfill should be @babel/polyfill.

None of this is well documented yet because Babel 7 is still an unstable beta.

Antoine Thornton
{
    "presets": [
        "env",
        "react"
    ],
    "test": [
        "jest"
    ]
}

Add the last block of code for "test" to you babel.rc Here is my .babelrc code for reference

   {
    "presets": [
        "env",
        "react"
    ],
    "plugins": [
        "transform-class-properties",
        "transform-object-rest-spread"
    ],
    "test": [
        "jest"
    ]
}

Here is my output from the command-line

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        9.264s
Ran all test suites.
Done in 12.99s.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!