Babel为什么会抛出Unknown选项:...孩子?

Mar*_*ski 2 babeljs babel-jest circleci-2.0

试图在CircleCi上运行构建,但测试失败。同样的东西在我的本地设备上运行完美。我的.babelrc配置:

{
  "presets": [
    "es2015",
    "react",
    "stage-2"
  ],
  "plugins": [
    "transform-class-properties",
    "react-hot-loader/babel",
    ["babel-plugin-transform-builtin-extend", {
      "globals": ["Error", "Array"]
    }],
    ["transform-runtime", {
      "polyfill": false,
      "regenerator": true
    }]
  ]
}
Run Code Online (Sandbox Code Playgroud)

我从circleCI获取错误:

yarn test v0.27.5
$ jest 
 FAIL  src/utils/service-helper.test.js
  ? Test suite failed to run

    ReferenceError: [BABEL] /home/circleci/repo/src/utils/service-helper.test.js: Unknown option: /home/circleci/repo/node_modules/react/index.js.Children. Check out http://babeljs.io/docs/usage/options/ for more information about options.

    A common cause of this error is the presence of a configuration options object without the corresponding preset name. Example:

    Invalid:
      `{ presets: [{option: value}] }`
    Valid:
      `{ presets: [['presetName', {option: value}]] }`
Run Code Online (Sandbox Code Playgroud)

任何想法都一样,因为相同的配置正在另一个项目上工作

log*_*yth 6

该错误无济于事,但问题是您的配置已包含react在预设列表中,但无法babel-preset-react在您的中找到该模块node_modules,因此它会像加载react预设一样加载模块本身。但是由于该"react"模块不是预设模块,Babel会抛出该异常。

最有可能的,你忘了名单babel-preset-react中的package.json