[Babel]:未知选项:foreign.Children

Posted

技术标签:

【中文标题】[Babel]:未知选项:foreign.Children【英文标题】:[Babel]: Unknown option: foreign.Children 【发布时间】:2016-12-14 14:38:40 【问题描述】:

我在使用这个脚本构建时遇到了这个错误:

webpack --colors --progress --watch --config --jsx-loader webpack.config.js

这是我的 package.json 文件:


  "dependencies": 
    "autoprefixer": "^6.0.3",
    "node-libs-browser": "^0.5.3",
    "object-assign": "4.0.1",
    "underscore": "1.8.3",
    "react": "0.14.7",
    "react-dom": "0.14.7",
    "react-router": "2.0.0",
    "history": "^1.17.0",
    "superagent": "^1.8.0",
    "react-addons-css-transition-group": "0.14.7",
    "react-bootstrap": "0.28.2",
    "react-select": "^1.0.0-beta9",
    "moment": "2.11.2",
    "truncate": "2.0.0",
    "superagent-promise-plugin": "2.1.0",
    "rrule": "2.1.0"
  ,
  "devDependencies": 
    "babel-core": "^6.13.2",
    "babel-loader": "^6.2.4",
    "babel-preset-es2015": "^6.13.2",
    "babel-preset-stage-0": "^6.5.0",
    "babel-runtime": "^6.11.6",
    "css-loader": "^0.23.1",
    "eslint": "^3.2.2",
    "eslint-config-defaults": "^9.0.0",
    "eslint-loader": "^1.5.0",
    "eslint-plugin-react": "^6.0.0",
    "extract-text-webpack-plugin": "^1.0.1",
    "file-loader": "^0.9.0",
    "html-webpack-plugin": "^2.22.0",
    "isparta-instrumenter-loader": "^1.0.1",
    "jsx-loader": "0.13.2",
    "less": "^2.3.1",
    "less-loader": "^2.2.3",
    "livereload": "^0.5.0",
    "null-loader": "^0.1.1",
    "postcss-loader": "^0.9.1",
    "raw-loader": "^0.5.1",
    "style-loader": "^0.13.1",
    "webpack": "^1.12.13",
    "webpack-livereload-plugin": "0.4.0"
  ,
  "babel": 
    "presets": [
      "stage-0",
      "es2015",
      "react"
    ]
  

还有我的 webpack.config.js

var webpack = require('webpack');
var path = require('path');
var LiveReloadPlugin = require('webpack-livereload-plugin')

module.exports = 
    output: 
        path: __dirname,
        filename: "bundle.js",
    ,
    resolve: 
        extensions: ['', '.js', '.jsx'],
        root: [
          path.resolve('./../../../../../../javascripts/modules')
        ],
        moduleDirectories:
        [
          './../../../../../../Javascripts/modules'
        ]
    ,
    module: 
        loaders: [
             test: /\.css$/, loader: "style!css" ,
            
                test: /\.less$/,
                loader: "style!css!less"
            ,
             test: /\.html$/, loader: 'raw', exclude: [/node_modules/, path.resolve('./../../../../../../Javascripts/modules')] ,
            
                test: /(\.jsx|\.js)$/,
                loader: 'babel',
                exclude: [/(node_modules|bower_components)/]
            ,
            
                test: /(\.jsx|\.js)$/,
                loader: "eslint-loader",
                exclude: [/node_modules/, path.resolve('./../../../../../../Javascripts/modules')]
            
        ]
    ,
    eslint: 
        configFile: './src/js/.eslintrc'
    ,
    entry: "./src/index.js",
    plugins: [
        new LiveReloadPlugin()
    ]
;

知道如何解决该错误吗?根据我的 Google 搜索,这是一个包版本控制问题,但这是我能够弄清楚的全部。

【问题讨论】:

在 jsonline 上,您的 json 显示有效 你的 webpack 配置是什么? 添加了我的 webpack.config.js 【参考方案1】:

您可能缺少 react babel presets npm 包。

试试这个:

npm i --save-dev babel-preset-react

【讨论】:

我试过了,现在我得到了一个通用的“未知选项:”。在完全删除“预设”部分之前,我一直收到错误消息。这三个预设有什么问题?【参考方案2】:

我最终回滚到 Babel 5,这个问题就消失了。对于以后可能会发现此问题的人来说,这不是一个很好的答案,但它适用于我的应用程序。

【讨论】:

你应该接受投票赞成的答案,因为它要好得多。

以上是关于[Babel]:未知选项:foreign.Children的主要内容,如果未能解决你的问题,请参考以下文章

Webpack / Babel / React 构建错误:“未知选项:foo/node_modules/react/react.js.Children”

如何修复 Vue 3 中的“错误:未知选项:devServer”[关闭]

如何用gulp-babel定位节点

如何在供应商捆绑包上使用 babel 的 `useBuiltIns: 'usage'` 选项?

Webpack 中 babel-loader 的“排除”选项

如何使用 npm babel 和 commandjs 将选项传递给脚本 [重复]