Tuesday, June 6, 2017

Invalid configuration object output.path is not an absolute path - Webpack

While i was practising the Nodejs with webpack recently i encountered an error, when i try to start the application using command npm start. I received 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 "./build" is not an absolute path!

Below is the snap shot of my webpack.config.js

 
module.exports = {  
  entry: ['./app/index.js'],  
  output: {  
   path: './build',  
   filename: 'bundle.js'  
  },  
  ....
  ...
 };  


The issue is due to path provided for the output, it is a relative path. output.path requires an absolute path, we need to convert it to an absolute path. To convert it into the absolute path, we will be using the path.resolve. Add the below code to your webpack.config.js, this should resolve the issue. Now you start the server, it will work like a charm

 
const path = require('path'); //in the top<
 module.exports = {  
  entry: ['./app/index.js'],  
  output: {  
   > path: 'path.resolve(__dirname, 'build'),'<  
   filename: 'bundle.js'  
  },  
 };  

Happy Programming...!!!

No comments:

Post a Comment