Omid
Omid

Reputation: 4715

webpack copy plugin gives error: output.filename is required, either in config file or as --output-filename

As a clean node project I do:

npm install webpack copy-webpack-plugin

and this is my webpack.config.js file:

var CopyWebpackPlugin = require('copy-webpack-plugin');
var path = require('path');

module.exports = {
  plugins: [
    new CopyWebpackPlugin([
      {
        from: 'src',
        to: 'dist'
      }
    ])
  ]
};

when I run npm run webpack get this error message:

$ npm run webpack

> [email protected] webpack /var/www/html/test
> webpack

/var/www/html/test/node_modules/webpack/bin/convert-argv.js:507
                throw new Error("'output.filename' is required, either in config file or as --output-filename");
                ^

Error: 'output.filename' is required, either in config file or as --output-filename
    at processOptions (/var/www/html/test/node_modules/webpack/bin/convert-argv.js:507:11)
    at processConfiguredOptions (/var/www/html/test/node_modules/webpack/bin/convert-argv.js:150:4)
    at module.exports (/var/www/html/test/node_modules/webpack/bin/convert-argv.js:112:10)
    at yargs.parse (/var/www/html/test/node_modules/webpack/bin/webpack.js:171:41)
    at Object.Yargs.self.parse (/var/www/html/test/node_modules/yargs/yargs.js:533:18)
    at Object.<anonymous> (/var/www/html/test/node_modules/webpack/bin/webpack.js:152:7)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Function.Module.runMain (module.js:684:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3

There is no specific solution around. how to solve it?

Upvotes: 1

Views: 936

Answers (1)

Syed
Syed

Reputation: 269

Try to add entry and output in webpack.config.js

const CopyWebpackPlugin = require('copy-webpack-plugin');
const path = require('path');

const rootPath = path.join(__dirname, '/');

module.exports = {
  entry: {
    main: `${rootPath}/src/main.js`,
  },

  output: {
    filename: '[name].[hash].js',
    path: `${rootPath}/dist`,
  },

  plugins: [
    new CopyWebpackPlugin([
      {
        from: 'src',
        to: 'dist'
      }
    ])
  ]
};

Hope this may help you.

Upvotes: 2

Related Questions