Search code examples
node.jswebpack

How to resolve Webpack error: Invalid configuration object


I am getting an error message I received in my webpack configuration. It states: "Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema".

Full text:

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.module has an unknown property 'loaders'. These properties are valid:
   object { exprContextCritical?, exprContextRecursive?, exprContextRegExp?, exprContextRequest?, noParse?, rules?, defaultRules?, unknownContextCritical?, unknownContextRecursive?, unknownContextRegExp?, unknownContextRequest?, unsafeCache?, wrappedContextCritical?, wrappedContextRecursive?, wrappedContextRegExp?, strictExportPresence?, strictThisContextOnImports? }
   -> Options affecting the normal modules (`NormalModuleFactory`).
 - configuration.resolve.extensions[0] should not be empty.
   -> A non-empty string

Solution

  • I figured out the way out for this kind of situations:

    First: create a file .babel-rc

        /* 
        ./.babelrc
    */  
    {
        "presets":[
            "es2015", "react"
        ]
    }
    

    well consider also this package json file:

    {
      "name": "theatherflix",
      "description": "",
      "main": "server.js",
      "scripts": {
        "webpack": "webpack --progress",
        "test": "echo \"Error: no test specified\" && exit 1",
        "build": "webpack --config webpack.config.js"
      },
      "author": "Nodeio Labs",
      "license": "GPL-3",
      "dependencies": {
        "@babel/preset-react": "^7.0.0-beta.51",
        "axios": "^0.18.0",
        "babel": "^6.23.0",
        "docker": "^1.0.0",
        "express": "^4.13.4",
        "extract-text-webpack-plugin": "^3.0.2",
        "find-process": "^1.1.0",
        "loader": "^2.1.1",
        "material-ui": "^0.20.1",
        "modules": "^0.4.0",
        "path": "^0.12.7",
        "react": "^0.14.7",
        "react-dom": "^0.14.7",
        "react-router": "^2.0.0",
        "redux": "^4.0.0",
        "redux-thunk": "^2.2.0",
        "ts-loader": "^4.4.1",
        "uuid": "^3.2.1",
        "webpack-dev-server": "^3.1.4"
      },
      "devDependencies": {
        "@babel/core": "^7.0.0-beta.51",
        "@babel/preset-env": "^7.0.0-beta.51",
        "babel-cli": "^6.26.0",
        "babel-core": "^6.26.3",
        "babel-loader": "^7.1.4",
        "babel-preset-es2015": "^6.24.1",
        "babel-preset-react": "^6.24.1",
        "babel-preset-stage-0": "^6.5.0",
        "fuse-box": "^3.2.2",
        "gulp-babel": "^7.0.1",
        "jsx-loader": "^0.13.2",
        "node-sass": "^4.9.0",
        "typescript": "^2.9.2",
        "webpack": "^4.12.0",
        "webpack-cli": "^3.0.2"
      }
    }
    

    *Use what you need in this pack of modules.

    Then I correct a few lines in my webpack:

    /*
        ./webpack.config.js
    */
    const path = require('path');
    module.exports = {
      mode: "none", 
      entry: './app/app.jsx',
      output: {
        path: path.resolve('public'),
        filename: 'bundle.js'
      },
      module: {
        rules: [{
            test: /\.css$/,
            use: [{
                loader: "style-loader"
              },
              {
                loader: "css-loader"
              }
            ]
          },
          {
            test: /\.js$/,
            exclude: /node_modules/,
            use: "babel-loader"
          }, {
            test: /\.jsx?$/,
            exclude: /node_modules/,
            use: "babel-loader"
          }
        ]
      }
    }
    

    And this is my app.jsx :

    var React = require('react');
    var ReactDOM = require('react-dom');
    var {Route, Router, IndexRoute, Main, About, MovieList, hashHistory} = require('react-router');
    var Main = require('./components/Main.jsx');
    var MovieList = require('./components/MovieList/MovieList.jsx');
    var About = require('./components/About/About.jsx');
    //import './app.scss';
    
    ReactDOM.render(
      <Router history={hashHistory}>
        <Route path="/" component={Main}>
        <Route path="about" component={About}/>
              <IndexRoute component={MovieList}/>
        </Route>
      </Router>,
      document.getElementById('app')
    );