Jest Babel错误:测试套件无法运行

时间:2020-06-03 14:45:42

标签: jestjs babeljs

这是我的package.json

{
    "name": "js-stack",
    "version": "1.0.0",
    "license": "MIT",
    "scripts": {
        "start": "babel-node src",
        "test": "eslint src && flow && jest --coverage"
    },
    "dependencies": {},
    "devDependencies": {
        "babel-cli": "^6.26.0",
        "babel-eslint": "^10.1.0",
        "babel-jest": "^26.0.1",
        "babel-preset-env": "^1.7.0",
        "babel-preset-flow": "^6.23.0",
        "babel-preset-react": "^6.24.1",
        "eslint": "^7.1.0",
        "eslint-config-airbnb": "^18.1.0",
        "eslint-plugin-compat": "^3.7.0",
        "eslint-plugin-flowtype": "^5.1.3",
        "eslint-plugin-import": "^2.20.1",
        "eslint-plugin-jsx-a11y": "^6.2.3",
        "eslint-plugin-react": "^7.19.0",
        "eslint-plugin-react-hooks": "^2.5.0 || ^1.7.0",
        "flow-bin": "^0.126.1",
        "jest": "^26.0.1",
        "react": "^16.13.1"
    },
    "browserslist": [
        "> 1%"
    ]
}

这是我的.babelrc文件

{
    "presets": [
        "env",
        "react",
        "flow"
    ]
}

虽然我得到了错误

Test suite failed to run

    Plugin/Preset files are not allowed to export objects, only functions.
In /Users/Codes/Javascript/js-stack/node_modules/babel-preset-react/lib/index.js

有人可以告诉我如何处理吗?我尝试了他们所说的一些解决方案,但仍然可以解决!如此迷茫!!!! THX

1 个答案:

答案 0 :(得分:0)

请记住以前有类似的问题。您是否尝试过使用babel.config.js摆脱.babelrc?这就是文件的外观

/* eslint-disable func-names */
module.exports = function (api) {
  const presets = [
    '@babel/preset-env',
    '@babel/preset-react',
    '@babel/preset-flow'
  ];
  const plugins = [];

  api.cache(false);

  return {
    presets,
    plugins
  };
};