Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's wrong with my Webpack config?

I started to use Webpack for a student project, but I'm stuck configuring Webpack to include React and Babel. Here's my node packages :

+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
`-- [email protected]

... And m'y webpack config file :

module.exports = {
    entry: ['babel-polyfill', './src/index.jsx'],
    output: {
        path: './build',
        filename: 'app.bundle.js'
    },
    module: {
        loaders: [
            {
                test: /\.jsx?$/,
                exclude: /node_modules/,
                loader: 'babel-loader',
                query: {
                    presets: ['es2015', 'react']
                }
            }
        ]
    }
};

But the webpack command show me this error :

ERROR in ./src/index.jsx
Module build failed: ReferenceError: [BABEL] C:\wamp\www\tripfighter\src\index.jsx: Unknown option: C:\wamp\www\tripfighter\node_modules\react\react.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: ['pluginName', {option: value}] }`

For more detailed information on preset configuration, please see http://babeljs.io/docs/plugins/#pluginpresets-options. (While processing preset: "C:\\wamp\\www\\tripfighter\\node_modules\\react\\react.js")
    at Logger.error (C:\wamp\www\tripfighter\node_modules\babel-core\lib\transformation\file\logger.js:41:11)
    at OptionManager.mergeOptions (C:\wamp\www\tripfighter\node_modules\babel-core\lib\transformation\file\options\option-manager.js:221:20)
    at C:\wamp\www\tripfighter\node_modules\babel-core\lib\transformation\file\options\option-manager.js:260:14
    at C:\wamp\www\tripfighter\node_modules\babel-core\lib\transformation\file\options\option-manager.js:329:22
    at Array.map (native)
    at OptionManager.resolvePresets (C:\wamp\www\tripfighter\node_modules\babel-core\lib\transformation\file\options\option-manager.js:270:20)
    at OptionManager.mergePresets (C:\wamp\www\tripfighter\node_modules\babel-core\lib\transformation\file\options\option-manager.js:259:10)
    at OptionManager.mergeOptions (C:\wamp\www\tripfighter\node_modules\babel-core\lib\transformation\file\options\option-manager.js:244:14)
    at OptionManager.init (C:\wamp\www\tripfighter\node_modules\babel-core\lib\transformation\file\options\option-manager.js:374:12)
    at File.initOptions (C:\wamp\www\tripfighter\node_modules\babel-core\lib\transformation\file\index.js:216:65)
    at new File (C:\wamp\www\tripfighter\node_modules\babel-core\lib\transformation\file\index.js:139:24)
    at Pipeline.transform (C:\wamp\www\tripfighter\node_modules\babel-core\lib\transformation\pipeline.js:46:16)
    at transpile (C:\wamp\www\tripfighter\node_modules\babel-loader\index.js:38:20)
    at Object.module.exports (C:\wamp\www\tripfighter\node_modules\babel-loader\index.js:131:12)
 @ multi main

(There is my sample index.jsx file)

import 'babel-polyfill';
import React from 'react';
import ReactDOM from 'react-dom';

ReactDOM.render(
  <h1>Hello, world!</h1>,
  document.getElementById('root')
);

import cats from './cats.js';
console.log(cats);

So the problem seems to come from my webpack.config.js, but I don't know why, despite having searched from many examples on the web. Can you help me ? Thanks !

like image 902
Thaledric Avatar asked Oct 26 '16 14:10

Thaledric


1 Answers

Your config is

presets: ['es2015', 'react']

but the only preset you've installed is

+-- [email protected]

So your answer is

npm install --save-dev babel-preset-react

Edit:

FYI, Babel 7 (when it is released) gives a much clearer error message about this, so that will make life easier for these cases.

like image 106
loganfsmyth Avatar answered Oct 12 '22 13:10

loganfsmyth