1

I'm getting an error with my Webpack configuration:

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.

  • configuration.output.path: The provided value "./" is not an absolute path!

This is my webpack.config.js:

var config = {
   entry: './main.js',
 
   output: {
      path:'./',
      filename: 'index.js',
   },
 
   devServer: {
      inline: true,
      port: 8080
   },
 
   module: {
      loaders: [
         {
            test: /\.jsx?$/,
            exclude: /node_modules/,
            loader: 'babel',
       
            query: {
               presets: ['es2015', 'react']
            }
         }
      ]
   }
}

module.exports = config;
Community
  • 1
  • 1

1 Answers1

4

Your path has to be absolute, not relative. To use the current directory, use the variable __dirname:

__dirname

The directory name of the current module. This the same as the path.dirname() of the __filename.

__dirname is not actually a global but rather local to each module.

Example: running node example.js from /Users/mjr

console.log(__dirname);
// Prints: /Users/mjr
console.log(path.dirname(__filename));
// Prints: /Users/mjr

Thus, it get's your current directory where the config is stored in as an absolute path and you apply it like so:

output: {
   path: __dirname,
   filename: 'index.js',
},

(Do note there are differences between ./ and __dirname as noted in this question. ./ refers to the current directory of the terminal calling the script and __dirname refers to the directory the script is stored in.)

Andrew Li
  • 55,805
  • 14
  • 125
  • 143
  • @ThilinaMullewidane If the answer did help, please consider clicking the checkmark next to the answer to accept it for future readers. Glad to help. – Andrew Li May 24 '17 at 03:30