Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid configuration object in webpack

Tags:

I am following Lynda.com - React.js essential training by Eve Porcello. In the video "Building with Webpack", I followed the steps author described exactly, but the "webpack" command failed giving the following error,

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema. - configuration.output.path: The provided value "dist/assets" is not an absolute path!

Following are my webpack.config.js and package.json files.

webpack.config.js

var webpack = require("webpack");  module.exports = {   entry: "./src/index.js",   output: {     path: "dist/assets",     filename: "bundle.js",     publicPath: "assets"   },   devServer: {     inline: true,     contentBase: "./dist",     port: 3000   },   module: {     loaders: [       {         test: /\.js$/,         exclude: /(node_modules)/,         loader: "babel-loader",         query: {           presets: ["latest", "stage-0", "react"]         }       }     ]   } } 

package.json

{   "name": "react-essential",   "version": "1.0.0",   "description": "A project focusing on React and related tools",   "main": "index.js",   "scripts": {     "start": "httpster -d ./dist -p 3000"   },   "author": "Indu Pillai",   "license": "MIT",   "devDependencies": {     "babel-cli": "^6.18.0",     "babel-loader": "^6.4.1",     "babel-preset-latest": "^6.16.0",     "babel-preset-react": "^6.16.0",     "babel-preset-stage-0": "^6.16.0",     "webpack": "^2.3.2",     "webpack-dev-server": "^2.4.2"   } } 

I repeated the steps again and again, but it's not working. I'm pretty new to this webpack thing, so I'm not able to find out what the problem really is, and what kind of absolute path it requires. I also tried an absolute path suggested by some answer to another (similar) question, but that didn't work.

Thank you!

like image 970
Indu Pillai Avatar asked Mar 27 '17 14:03

Indu Pillai


People also ask

How do you fix Invalid configuration object webpack has been initialized using a configuration object that does not match the API schema?

I changed loaders to rules in the webpack. config. js file and updated the packages html-webpack-plugin , webpack , webpack-cli , webpack-dev-server to the latest version then it worked for me!

Where is Webpack config JavaScript?

To answer your specific question, the webpack configuration is stored wherever your global node_modules are installed; on Windows this is typically %AppData%\Roaming\npm\node_modules\powerbi-visuals-tools\lib\webpack. config. js.


2 Answers

This will compile with latest webpack - as of Apr 10, 2017:

var webpack = require("webpack");  module.exports = {     entry: __dirname + "/src/index.js",     output: {         path: __dirname + "/dist/assets",         filename: "bundle.js",         publicPath: "assets"     },     devServer: {         inline: true,         contentBase: __dirname + "/dist",         port: 3000     },     module: {         rules: [{             test: /\.js$/,             loader: ["babel-loader"],         }]     } } 
like image 109
Jean-Louis Brunet Avatar answered Dec 20 '22 13:12

Jean-Louis Brunet


I am doing the same course as you and I had to do the following to get Webpack to output the bundle.js file correctly:

  1. Uninstall the latest webpack (2, if you just used npm install webpack)
  2. Then in terminal run npm install -g [email protected] (she recommends using sudo npm install -g so it's up to you on that one to use sudo or not)
  3. The next issue few issues webpack was throwing may only apply to me but I had to require('path') because I got non-resolving path errors, and also had to npm install babel-loader because it wasn't being loaded through the package.json file for whatever reason, that also needed a path.resolve addition for the node_modules folder
  4. My webpack.config file looks like the following now:

    const webpack = require('webpack'); const path = require('path');  module.exports = {     entry: path.resolve(__dirname, './src/index'),     output: {         path: path.resolve(__dirname, './dist/assets'),         filename: 'bundle.js',         publicPath: 'assets'     },     devServer: {         inline: true,         contentBase: path.resolve(__dirname, './dist'),         port: 3000     },     module: {         loaders: [{             test: /\.js$/,             exclude: /(node_modules)/,             loader: path.resolve(__dirname, './node_modules/babel-loader'),             query: {                 presets: ['latest', 'stage-0', 'react']             }         }]     } } 
  5. Finally, running webpack --display-error-details showed me what the errors were, but the config file I pasted here worked for me in the end.

It should be noted that this will (hopefully) allow you to finish the course itself, but it won't help you learn what was updated or needs to be migrated in order to stay current and use Webpack 2. There are other answers here that deal with migrating that should be looked into as well.

Hope this helps you!

like image 38
rgjr Avatar answered Dec 20 '22 12:12

rgjr