babeljs - 为什么 Babel 抛出 Unknown option : . .. Children?

标签 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
    }]
  ]
}

我从 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}]] }`

当相同的配置在另一个项目上工作时,知道发生了什么

最佳答案

报错没有用,问题是你的配置在预设列表里有react,但是找不到babel-preset-react模块你的 node_modules,所以它正在加载 react 模块本身,就好像它是一个预设。但是由于 “react” 模块不是预设,所以 Babel 抛出。

很可能,您忘记了在 package.json 中列出 babel-preset-react

关于babeljs - 为什么 Babel 抛出 Unknown option : . .. Children?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50659921/

相关文章:

FaSTLane Match 无法使用个人访问 token 和用户名连接

git - 代理 key RSA SHA256 : . .. 返回不正确的签名类型

javascript - 将遗留库迁移到 ES2015 风格的模块

jestjs - Jest --watch 始终运行所有测试

reactjs - 如何使用使用 es6 的 node_modules 设置 jest

ecmascript-6 - 带有 ES6 模块的 babel-jest

javascript - 使用 webpack 和 babel 的动态 import() 语法错误

javascript - 无法通过 npm 脚本运行 babel "babel: command not found"

javascript - 如果使用 babel 进行编译,是否需要 typescript 项目引用? (使用 Webpack 的 Electron 项目)

Golang CircleCI 2.0 测试失败,信号为 : killed